Home > Back-end >  How can I request data with device access code for default gateway router 5268AC?
How can I request data with device access code for default gateway router 5268AC?

Time:03-13

I would like to write a script that can collect data from the router, in this case 5268AC. So far, I've been able to use response.get() to get information from URLs that do not require device access code to see information. To get information about Wifi, for example, the default SSID, I need to enter the access code located on the router via the browser. I keep getting error 500 when trying request.post(url).

url="http://192.168.1.254/xslt?PAGE=C_2_1"

From inspection, I believe this is the form I'm trying fill. The key value is ADM_PASSWORD.

              <h2>Login</h2>
              <p>Device access code required. Please enter the device access code, then click Submit.</p>
              <form name="pagepost" method="post" action="xslt?PAGE=login_post" id="pagepost">
                <input type="hidden" name="NONCE" value="0abc59f54121398" />
                <input type="hidden" name="THISPAGE" value="" />
                <input type="hidden" name="NEXTPAGE" value="C_2_1" />
                <input type="hidden" name="CMSKICK" value="" />
                <div>
                  <div >
                    <label for="ADM_PASSWORD">Access code</label>
                    <span>
                      <input type="password" id="ADM_PASSWORD" name="ADM_PASSWORD" size="16" maxlength="16" autofocus="autofocus" required="required" autocomplete="off" />
                    </span>
                  </div>
                </div>
                <p align="right">
                  <input type="submit"  value="Submit" />

I tried this but got 500 status error.

payload = { 'ADM_PASSWORD':'*access code*' }
response = requests.post(url, headers=headers, data=payload)

Is there a way to be able to collect information via requests instead of using GUI?

CodePudding user response:

First in Chrome/Firefox you can use DevTools (tab: Network) to see what browser sends when you login.

Form has action="xslt?PAGE=login_post" so you should send to

url = "http://192.168.1.254/xslt?PAGE=login_post"

It is relative path - so if you would open page ie. http://http://192.168.1.254/login/ then it would need

url = "http://192.168.1.254/login/xslt?PAGE=login_post"

You have to send all input which you see in form - especially hidden.
Sometimes it may need even submit.

And you should use name= as key, not id=

payload = { 
    'NONCE': '0abc59f54121398',
    'THISPAGE': '',
    'NEXTPAGE': 'C_2_1',
    'CMSKICK': '',
    'ADM_PASSWORD': '*access code*' 
}

If you use post() with data= or json= then it should automatically set correct value in Content-Type and Content-Length and you don't have to set it in headers.


You may also first run get() to page with form because it may set cookies which server/device may also check.


Problem can be only if page uses JavaScript to generate some extra data in form and it would need to use Selenium - but it would need to write all with Selenium


Sometimes I send request to https://httpbin.org/post and it sends me back all headers, cookies, post data which it get from me and I can compare it with data which I see in DevTools.

Evetually I use local proxy server Charles and use it in browser and in Python to see if code sends the same data as browser.

  • Related