我如何知道要为该D-link路由器页面输入什么有效载荷?

时间:2019-02-13 06:04:31

标签: python-2.7 windows-10 router

我只是涉猎。

我一直在尝试通过请求库登录到路由器,但是不确定是否需要在有效负载中添加其他内容。它没有CSR或类似的东西。

在Windows 10上使用Python 2.7

这是我的代码:

import requests
import sys

USERNAME = 'admin'
PASSWORD = 'password'

LOGIN_URL = "http://192.168.0.1/info/Login.html"
URL = "http://192.168.0.1/QoS.html"
payload = {
    'admin_Password': PASSWORD
    }
with requests.Session() as c:
    c.post(LOGIN_URL, data = payload)
    page = c.get(URL)
    print page.content

这是登录页面中的HTML:

<<html xmlns="http://www.w3c.org/1999/xhtml"><head><style id="stndz-style">div[class*="item-container-obpd"], a[data-redirect*="paid.outbrain.com"], a[onmousedown*="paid.outbrain.com"] { display: none !important; } a div[class*="item-container-ad"] { height: 0px !important; overflow: hidden !important; position: absolute !important; } div[data-item-syndicated="true"] { display: none !important; } .grv_is_sponsored { display: none !important; } .zergnet-widget-related { display: none !important; } </style> <title>D-LINK</title> <meta http-equiv="X-UA-Compatible" content="IE=9"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/css"> <link rel="stylesheet" type="text/css" href="/css/jquery.selectbox.css?v=20161019093949"> <link rel="stylesheet" type="text/css" href="/css/style_h.css?v=20161019093949" media="all"> <script type="text/javascript" charset="utf-8" src="/js/initialJQ.js?v=20161019093949"></script><script type="text/javascript" charset="utf-8" src="/js/jquery-1.11.1.min.js"></script><script type="text/javascript" charset="utf-8" src="/js/jquery.selectbox-0.2_new.js?v=20161019093949"></script><script type="text/javascript" charset="utf-8" src="/js/jquery.stringify.js?v=20161019093949"></script><script type="text/javascript" charset="utf-8" src="/js/jquery.cookie.js?v=20161019093949"></script> <script type="text/javascript" charset="utf-8" src="/js/initialJSDefault.js?v=20161019093949"></script><script type="text/javascript" charset="utf-8" src="/js/comm.js?v=20161019093949"></script><script type="text/javascript" charset="utf-8" src="/js/hmac_md5.js?v=20161019093949"></script><script type="text/javascript" charset="utf-8" src="/js/libajax.js?v=20161019093949"></script><script type="text/javascript" charset="utf-8" src="/js/i18n.js?v=20161019093949"></script><script type="text/javascript" charset="utf-8" src="/js/configuration/DeviceConfig.js?v=20161019093949"></script>  <script type="text/javascript" charset="utf-8" src="/js/Login.js?v=20161019093949"></script><script type="text/javascript" charset="utf-8" src="../config/features.js?v=20161019093949"></script> <script type="text/javascript" charset="utf-8" src="/js/SOAP/SOAPAction.js?v=20161019093949"></script> <script type="text/javascript" charset="utf-8" src="/js/SOAP/SOAPDeviceSettings.js?v=20161019093949"></script> <script type="text/javascript" charset="utf-8" src="/js/initEnv.js?v=20161019093949"></script> <script type="text/javascript" charset="utf-8" src="/js/SOAP/SOAPLogin.js?v=20161019093949"></script> <script type="text/javascript">var HasCAPTCHA=0;var ShowShareportLink=0;var init=initEnv();$(document).ready(function(){init.done(function(){showDeviceInfo()})});function showDeviceInfo(){var a=getDeviceSettings.PresentationURL;a=a.replace("http://","");a=a.split(/[\s.]+/);var b=a[a.length-2].toLowerCase();if(window.location.hostname.search(b)!=-1||window.location.hostname.substr(0,8)=="192.168."||window.location.hostname.substr(0,3)=="10."||window.location.hostname.substr(0,7)=="172.16."){ShowShareportLink=1}document.getElementById("modelName").innerHTML=getDeviceSettings.ModelName;document.getElementById("HWversion").innerHTML=getDeviceSettings.HardwareVersion;document.getElementById("FWversion").innerHTML=getDeviceSettings.FirmwareVersion;if(getDeviceSettings.SharePortStatus!="true"||ShowShareportLink==0){document.getElementById("sharePortAccess").style.display="none"}if(getDeviceSettings.CAPTCHA=="true"){document.getElementById("logIn_captcha").style.display="table";generate_Captcha();HasCAPTCHA=1}else{document.getElementById("logIn").style.display="table";HasCAPTCHA=0}var c=localStorage.getItem("language");$("#Language").selectbox("detach");$("#Language").val(c);$("#Language").selectbox({width:120});document.getElementById("main").style.display="inline";document.getElementById("admin_Password").disabled=false;document.getElementById("admin_Password_with_Captcha").disabled=false;$("#logIn_btn").attr("class","styled_button_s").prop("disabled",false);$("#logIn_btn_c").attr("class","styled_button_s").prop("disabled",false);if(getDeviceSettings.CAPTCHA=="true"){document.getElementById("admin_Password_with_Captcha").focus()}else{document.getElementById("admin_Password").focus()}}function OnClickLogin(){var b=null;var a=null;if(HasCAPTCHA==0){b=document.getElementById("admin_Password").value;a=""}else{b=document.getElementById("admin_Password_with_Captcha").value;a=document.getElementById("input_Captcha").value}document.getElementById("admin_Password").disabled=true;document.getElementById("admin_Password_with_Captcha").disabled=true;$("#logIn_btn").attr("class","styled_button_dis").prop("disabled",true);$("#logIn_btn_c").attr("class","styled_button_dis").prop("disabled",true);doLogin(b,a).done(function(){var c=sessionStorage.getItem("RedirectUrl");if((c==null)||(c.indexOf("Login.html")>0)||(c.indexOf("html")<0)){window.location.href="/IndexHome.html"}else{window.location.href=c}}).fail(function(){document.getElementById("admin_Password").disabled=false;document.getElementById("admin_Password_with_Captcha").disabled=false;$("#logIn_btn").attr("class","styled_button_s").prop("disabled",false);$("#logIn_btn_c").attr("class","styled_button_s").prop("disabled",false);if(HasCAPTCHA==1){alert(I18N("j","Invalid password or captcha, please try again."));document.getElementById("admin_Password_with_Captcha").value="";document.getElementById("input_Captcha").value="";document.getElementById("admin_Password_with_Captcha").focus();generate_Captcha()}else{alert(I18N("j","Invalid password, please try again."));document.getElementById("admin_Password").value="";document.getElementById("admin_Password").focus()}})}function generate_Captcha(){if(navigator.cookieEnabled){var b=COMM_RandomStr(10);document.cookie="uid="+b+"; path=/";sessionStorage.setItem("Cookie",b)}var a=GetAjaxObj("captcha");a.release();a.createRequest();a.onCallback=function(c){switch(c.Get("/captcha/result")){case"OK":self.captcha=c.Get("/captcha/message");document.getElementById("captcha_image").innerHTML="<img src="+self.captcha+"?"+COMM_RandomStr(6)+" />";break}a.release()};a.setHeader("Content-Type","application/x-www-form-urlencoded");a.sendRequest("/captcha.cgi","DUMMY=YES")}function switch_Language(a){sessionStorage.removeItem("langPack");localStorage.setItem("language",a);location.reload()}function detect_KeyValue(b){var a=window.event?b.keyCode:b.which;if(a==13){document.getElementById("logIn_btn").click();document.getElementById("logIn_btn_c").click()}};</script></head>  <body id="main" style="display: inline;" class=" hasGoogleVoiceExt"> <div id="wrapper"> <div id="Lheader"> <div id="logo"> <img id="DLink_logo" src="/image/logo_2.gif" width="105" height="95"> </div> <table class="versionTable" id="versionTable" border="0" cellspacing="0"> <tbody> </tbody><thead> <tr><td><script>I18N("h","Model Name");</script>Model Name:&nbsp;<label id="modelName">DIR-880L</label></td> <td><script>I18N("h","Hardware Version");</script>Hardware Version:&nbsp;<label id="HWversion">A1</label></td> <td><script>I18N("h","Firmware Version");</script>Firmware Version:&nbsp;<label id="FWversion">1.08WW</label></td> <td align="right"><script>I18N("h","Language");</script>Language:</td> <td> <div class="styled-select"> <select name="Language" id="Language" onchange="switch_Language(this.value)" sb="20442171" style="display: none;"> <option value="en-us">English</option> <option value="zh-tw">繁體中文</option> <option value="zh-cn">简体中文</option> <option value="ko-kr">한국</option> <option value="fr-fr">français</option> <option value="pt-br">português</option> <option value="es-es">Español</option> <option value="it-it">Italiano</option> <option value="de-de">Deutsch</option> <option value="ru-ru">русский</option> </select><div id="sbHolder_20442171" class="sbHolder" style="width:120px"><a id="sbToggle_20442171" href="#" class="sbToggle"></a><a id="sbSelector_20442171" href="#" class="sbSelector" style="width:90px">English</a><ul id="sbOptions_20442171" class="sbOptions" style="width: 120px; display: none;"><li><a href="en-us" rel="en-us" class="sbFocus">English</a></li><li><a href="zh-tw" rel="zh-tw">繁體中文</a></li><li><a href="zh-cn" rel="zh-cn">简体中文</a></li><li><a href="ko-kr" rel="ko-kr">한국</a></li><li><a href="fr-fr" rel="fr-fr">français</a></li><li><a href="pt-br" rel="pt-br">português</a></li><li><a href="es-es" rel="es-es">Español</a></li><li><a href="it-it" rel="it-it">Italiano</a></li><li><a href="de-de" rel="de-de">Deutsch</a></li><li><a href="ru-ru" rel="ru-ru">русский</a></li></ul></div> </div> </td> </tr></thead>  </table> </div> <div id="content"> <br> <div id="logIn" style="display: table;"> <table class="logInTable" id="logInTable" border="0" cellspacing="0"> <tbody> </tbody><thead> <tr> <th><script>I18N("h","Admin Password");</script>Admin Password:</th> </tr> <tr> <td><input class="styled-text" type="password" name="admin_Password" size="27" id="admin_Password" onkeydown="detect_KeyValue(event)" style="background-image: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACIUlEQVQ4EX2TOYhTURSG87IMihDsjGghBhFBmHFDHLWwSqcikk4RRKJgk0KL7C8bMpWpZtIqNkEUl1ZCgs0wOo0SxiLMDApWlgOPrH7/5b2QkYwX7jvn/uc//zl3edZ4PPbNGvF4fC4ajR5VrNvt/mo0Gr1ZPOtfgWw2e9Lv9+chX7cs64CS4Oxg3o9GI7tUKv0Q5o1dAiTfCgQCLwnOkfQOu+oSLyJ2A783HA7vIPLGxX0TgVwud4HKn0nc7Pf7N6vV6oZHkkX8FPG3uMfgXC0Wi2vCg/poUKGGcagQI3k7k8mcp5slcGswGDwpl8tfwGJg3xB6Dvey8vz6oH4C3iXcFYjbwiDeo1KafafkC3NjK7iL5ESFGQEUF7Sg+ifZdDp9GnMF/KGmfBdT2HCwZ7TwtrBPC7rQaav6Iv48rqZwg+F+p8hOMBj0IbxfMdMBrW5pAVGV/ztINByENkU0t5BIJEKRSOQ3Aj+Z57iFs1R5NK3EQS6HQqF1zmQdzpFWq3W42WwOTAf1er1PF2USFlC+qxMvFAr3HcexWX+QX6lUvsKpkTyPSEXJkw6MQ4S38Ljdbi8rmM/nY+CvgNcQqdH6U/xrYK9t244jZv6ByUOSiDdIfgBZ12U6dHEHu9TpdIr8F0OP692CtzaW/a6y3y0Wx5kbFHvGuXzkgf0xhKnPzA4UTyaTB8Ph8AvcHi3fnsrZ7Wore02YViqVOrRXXPhfqP8j6MYlawoAAAAASUVORK5CYII=&quot;); background-repeat: no-repeat; background-attachment: scroll; background-size: 16px 18px; background-position: 98% 50%; cursor: auto;"></td> </tr> </thead>  </table> <center><button type="button" id="logIn_btn" class="styled_button_s" onclick="OnClickLogin()"><script>I18N("h","Log In");</script>Log In</button></center> </div> <div id="logIn_captcha" style="display:none"> <table id="logInTable_captcha_left" border="0" cellspacing="0"> <tbody> </tbody><thead> <tr> <th><script>I18N("h","Admin Password");</script>Admin Password:</th> </tr> <tr> <td><input class="styled-text" type="password" name="admin_Password_with_Captcha" size="27" id="admin_Password_with_Captcha"></td> </tr> </thead>  </table> <table id="logInTable_captcha_right" border="0" cellspacing="0"> <thead> <tr> <td><script>I18N("h","Type the characters you see in the picture below.");</script>Type the characters you see in the picture below.</td> </tr> <tr> <td align="center" height="50px"><input class="styled-text" type="text" name="input_Captcha" size="15" id="input_Captcha"></td> </tr> <tr> <td align="center" height="30px"> <label id="captcha_image"></label> <img id="refresh_button" src="/image/refresh.png" width="37" height="37" onclick="generate_Captcha()"> </td> </tr> </thead> <tbody></tbody> </table> <center><button type="button" id="logIn_btn_c" class="styled_button_s" onclick="OnClickLogin()"><script>I18N("h","Log In");</script>Log In</button></center> </div> </div> <br> <div id="sharePortAccess"><script>I18N("h","To access your storage with SharePort Web Access,");</script>To access your storage with SharePort Web Access, <a target="_blank" href="http://shareport.local/"><script>I18N("h","click here.");</script>click here.</a></div> <br> <br> <br> <br> <br> <br> <br> <div id="footer_login"> <div id="copyright"><script>I18N("h","COPYRIGHT");</script>COPYRIGHT © 2015 D-Link</div> <div id="eula"><a target="_blank" href="EULA.html"><script>I18N("h","License Agreement");</script>License Agreement</a></div> </div> </div>  </body></html>>

还有一个用于登录的按钮,不确定是否有帮助。

<button type="button" id="logIn_btn" class="styled_button_s" onclick="OnClickLogin()"><script>I18N("h","Log In");</script>Log In</button>

页面本身的图像。

Log in page for the router

我的错误代码:

Traceback (most recent call last):
File "C:\Users\Desktop\Google_Drive\Projects\Python\Router.py", line 14, in <module>
 c.post(LOGIN_URL, data = payload)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 581, in post
 return self.request('POST', url, data=data, json=json, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 533, in request
 resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 646, in send
 r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 498, in send
 raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine("''",))

0 个答案:

没有答案