danni123

I want to write a program for restarting router.

I¡¯ll try to describe the process of restarting a router:
  1. Start the browser.
  2. Enter router¡¯s IP.
  3. Inset password.
  4. Click on ¡°Apply¡± (menu panel) button and wait for 30 seconds countdown , for this period of time the web page should be opened for restart process to complete.
  5. Close the browser.
The program should do all this of course in background (without opening browsers) .

How this can be done and what tools should I use: webbrowser Control, HttpWebRequest or DOM technology

Thanks for help and suggestions.


Re: .NET Framework Networking and Communication How to access router's webpage interface and restart it?

Mike Flasko

The APIs you will likely want to use is HttpWebRequest.  Essentially you will need to make an HTTP request to the IP address the router is listening on.  Take a network capture while using the router admin page via your browser, then analyze the capture to see what type of http requests you will need to make from your application.

Some network applicances are also accessible using protocols outside raw HTTP (web services, SNMP, etc).  Check your router manual / admin docs for more information






Re: .NET Framework Networking and Communication How to access router's webpage interface and restart it?

danni123

Mike Flasko wrote:

Take a network capture.



What is a network capture




Re: .NET Framework Networking and Communication How to access router's webpage interface and restart it?

RizwanSharp

He means to say that you should use some Network Sniffing tool like Ethreal (A Free open source tool) to sniff network packets after you do it manually with IE or some other browser, then reproduce the same Http command using HttpWebRequest class. This will do your work.

Note: Search google for Ethreal.

I hope this will help.

Best Regards,

Rizwan aka RizwanSharp






Re: .NET Framework Networking and Communication How to access router's webpage interface and restart it?

danni123

And what about DOM architecture
One VB developer told me something about
MSHTML.HTMLDocument ...
Any idea

p.s. firefox has a DOM inspector tool, will it do the sniffing part





Re: .NET Framework Networking and Communication How to access router's webpage interface and restart it?

danni123

LOL, using firefox¡¯s DOM inspector, I¡¯ve looked into this ¡°Apply¡± button, it has a huge tree with parameters and attributes but one of them was:

Onclick GURL('restart.htm')

I thought this page restarts the router, but when I opened it with browser, it just shows the frame with countdown timer to 0 without restarting it.

So I still can¡¯t find what triggers it.





Re: .NET Framework Networking and Communication How to access router's webpage interface and restart it?

danni123

Ok,
I used SmartSniff program to analyze packets.
Here I put links to "Packets Stream Report " of relevant to "restart" code files (I've uploaded them to google docs).
So please tell me what should I take from them. (if something is missing, tell an I'll add)

login.htm

menu_admin.htm
I guess this is the main window - please notice button with caption "Apply" named = "restart" - this what I need


All related to restart:

restart.htm

stbar_restart.htm

iframerestart.htm

p.s.
One of generated files (not included here) contains router's password as plain text! LOL!




Re: .NET Framework Networking and Communication How to access router's webpage interface and restart it?

danni123

Well this is what I¡¯ve done so far:


ASCIIEncoding encoding = new ASCIIEncoding();

string postData = "page=login&logout=2&login_password=router1";

byte[] data = encoding.GetBytes(postData);

// Prepare web request...

HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://192.168.1.1/login.htm"); myRequest.Method = "POST";

myRequest.ContentType = "application/x-www-form-urlencoded";

myRequest.ContentLength = data.Length;

Stream newStream = myRequest.GetRequestStream();

// Send the data.

newStream.Write(data, 0, data.Length);

newStream.Close();


// Get the response

HttpWebResponse response =

(HttpWebResponse)myRequest.GetResponse();


The problem: I get an exception

HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();

I get an exception: The remote server returned an error: (501) Not Implemented.

What can be done





Re: .NET Framework Networking and Communication How to access router's webpage interface and restart it?

RizwanSharp

501 Not Implemented

The server does not support the functionality required to fulfill the request. This is the appropriate response when the server does not recognize the request method and is not capable of supporting it for any resource.

I saw your log menu_admin.htm and I hope that was done manually using a browser which is:

GET /menu_admin.htm HTTP/1.1
Host: 192.168.1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://192.168.1.1/main_frame_admin.htm

But you are doing a Post using "myRequest.Method = "POST";"

For this to work you need to generate the same output that was generated by IE when accessin that webpage.

Try to do some work on sniffing and to build your command programatically alike.

I hope you'll be successful soon.

Best Regards,

Rizwan aka RizwanSharp






Re: .NET Framework Networking and Communication How to access router's webpage interface and restart it?

danni123

Everything works now!
The problem was posting to wrong URL! it should be http://192.168.1.1/password.cgi.

I have another question regarding parsing html files, but I'll ask it general sub forum.

Thank you all.