LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   script for interacting with a router's admin website (http://www.linuxquestions.org/questions/programming-9/script-for-interacting-with-a-routers-admin-website-4175431910/)

oneindelijk 10-12-2012 04:08 PM

script for interacting with a router's admin website
 
Hi,

We are testing a wireless device on a lot of commonly used wireless routers.
For that purpose it would be efficient if we could somehow automate the process of changing the routers parameters to different settings and save them.
They're not high-end routers so they don't have snmp or terminal functionality.

What possible options could we try ?

Edit: I think one way to do it would be to send the html commands to the router on port 8080 (or 80 for some)
Is that possible ?

pan64 10-14-2012 04:21 AM

you would - at least - say the type of that router. jdownloader has a similar functionality, it is implemented in java, probably you can get some tips from there.

theNbomr 10-14-2012 10:44 AM

Many different kinds of devices these days have built-in HTTP servers to provide a monitoring and/or configuration tool for end users. In many cases, it is fairly simple to craft an HTTP client that interacts independently with the server (device; router in your case). However, many devices rely on the likes of Javascript, Java applets, and other client-side scripting, and some even rely on browser-specific behavior (came across one the other day that wouldn't work without Internet Explorer).
It should be easy to see whether your device uses these languages. Just use wget or curl to fetch a page or two from the device, and examine the reply. If it is all plain HTML (some CSS is okay), then you're probably good to go. If there is Javascript &/or Java applets uploaded, then you're probably hooped. Once you've established feasibility, you will need to use a combination of your wget/curl tool set, as well as a conventional browser to see what URLs and arguments are used.
Creating a smart HTTP client requires a reasonably complete programming language such as Perl, Python, or C. You will need to be able to parse HTML, and this can be tricky, but there are existing libraries for most languages to help out. Perl is my preferred tool for this task. You will need to divine by inspection and trial and error, what responses the device expects, as well as how to send them; what port(s) to use, what HTTP methods are used, and what parameters and values are required. With luck, most of the possibilities will be evident by looking at the HTML that you capture from the device.

--- rod.

oneindelijk 10-15-2012 06:04 AM

Quote:

Originally Posted by pan64 (Post 4805224)
you would - at least - say the type of that router. jdownloader has a similar functionality, it is implemented in java, probably you can get some tips from there.

I don't understand your answer...
After visiting the site, I still don't (and I can read spanish!).
Could you clarify a bit ?

oneindelijk 10-15-2012 06:08 AM

Quote:

Originally Posted by theNbomr (Post 4805397)
Creating a smart HTTP client requires a reasonably complete programming language such as Perl, Python, or C. You will need to be able to parse HTML, and this can be tricky, but there are existing libraries for most languages to help out. Perl is my preferred tool for this task. You will need to divine by inspection and trial and error, what responses the device expects, as well as how to send them; what port(s) to use, what HTTP methods are used, and what parameters and values are required. With luck, most of the possibilities will be evident by looking at the HTML that you capture from the device.

Thanks for your fast and complete response.
However, we don't have the time and skills to take this approach.
We've decided to simply export the different configurations from the routers and have an autoclicker load these different files on command...

pan64 10-15-2012 06:47 AM

Quote:

Originally Posted by oneindelijk (Post 4805990)
I don't understand your answer...
After visiting the site, I still don't (and I can read spanish!).
Could you clarify a bit ?

jDownloader includes a feature similar you requested. There is also a script generator to be able to handle any kind of router. So actually the problem is solved, you only need to use that solution (if it was really suitable).

Another solution could be to upgrade the software of the router (that's why I asked the type). In this case you may have ssh into the router.

oneindelijk 10-22-2012 03:51 PM

Quote:

Originally Posted by pan64 (Post 4806021)
Another solution could be to upgrade the software of the router (that's why I asked the type). In this case you may have ssh into the router.

We are testing our device for consumers. So we need to test it with the routers in their default firmwares.
What do you mean that jDownloader can 'handle' the routers ? Can it automatically load a previously saved configuration file ?
(Automatically means in this case, triggered by a command from another script ?)

asimba 10-23-2012 09:50 AM

you could use one of the linux boxes for this.

You could write a script which would telnet/ssh into this kinda router - get environemnt variables/set environement variables - check for changes/make changes and logout.

I dont think it is that cumbersome.

oneindelijk 10-23-2012 10:28 AM

Quote:

Originally Posted by asimba (Post 4813046)
you could use one of the linux boxes for this.

You could write a script which would telnet/ssh into this kinda router - get environemnt variables/set environement variables - check for changes/make changes and logout.

I dont think it is that cumbersome.

I think most routers don't support ssh ?
I've been trying to use curl, mainly to upload a previously saved configuration file (we saved several, all with different settings), but I can't figure out the correct syntax.
This is the command I've deducted from the http header, but I don't think it is correct.
If anyone would be able to correct this syntax, it would be a huge step forward
curl --trace -F restore=@Radio_OFF.cfg -F submit_button=Restore -F wait_time=21 http://192.168.1.103:8080/restore.cgi -u admin:password

This is the http header:
Code:

POST /restore.cgi HTTP/1.1
Host: 192.168.1.103:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://192.168.1.103:8080/Restore.asp
Authorization: Basic YWRtaW46cGFzc3dvcmQ=
Content-Type: multipart/form-data; boundary=---------------------------18061178356874499221977202731
Content-Length: 9214
-----------------------------18061178356874499221977202731
Content-Disposition: form-data; name="submit_button"

Restore
-----------------------------18061178356874499221977202731
Content-Disposition: form-data; name="small_screen"


-----------------------------18061178356874499221977202731
Content-Disposition: form-data; name="wait_time"

21
-----------------------------18061178356874499221977202731
Content-Disposition: form-data; name="restore"; filename="Radio_OFF.cfg"
Content-Type: text/txt

Salted__.Sx~*S _!l3Uak&2*lw\.@w*bEʾ.=a94$Y0n}yG
:s-'Jʆr
E7l6A<.k+;g,y0.F~r7S:$AHןO8FH
< 18VZft%/{*Jt
\3}(, ~iFρ[M VX|j'
GJx/ò ՖdUbE!U<DI/E)͵/ta3" MpP_8%



All times are GMT -5. The time now is 01:21 PM.