Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi friends,

When i'm connecting (with Tcpclient classe) to my router 192.168.1.1 he ask me about Password,See here [^]and the code used is :

TcpClient tcpclient = new TcpClient();
            try
            {
                tcpclient.Connect("192.168.1.1", 23);
                NetworkStream ns = tcpclient.GetStream();
 

                byte[] inStream = new byte[10025];
                ns.Read(inStream, 0, (int)tcpclient.ReceiveBufferSize);
                string returndata = System.Text.Encoding.ASCII.GetString(inStream);
                Console.WriteLine("Data from Server : " + returndata);
                //string password = "admin";
                
 
                
                byte[] msg = Encoding.ASCII.GetBytes("admin");
                ns.Write(msg, 0, msg.Length);
                ns.Flush();
 
                
            }
            catch
            {
                
            }


and i want here to login to my router with my password "admin" automatically in the code
how can i do it ?

Thank you
Posted
Updated 30-Sep-11 5:41am
v2

Your see here[^] link isn't working but I assume you get a web form and need to fill in the password and post it back to the router. You need to create a response like a webpage in the browser would do when you click the submit button. You can create it using the HttpWebResponse class. Have a look at the links for an example and more info.

http://www.dijksterhuis.org/simple-class-to-submit-post-a-web-form-from-csharp/[^]

http://stackoverflow.com/questions/793755/how-to-fill-forms-and-submit-with-webclient-in-c[^]

Good luck!
 
Share this answer
 
v2
Comments
carlos pin 30-Sep-11 11:48am    
Thank you Nijboer
http://www6.0zz0.com/2011/09/25/09/809657530.png

If you can help me, i want login with Tcpclient class help me Plzz
E.F. Nijboer 30-Sep-11 14:25pm    
The data from the server (in your screenshot) looks somewhat strange. The screenshot also doesn't tell me enough about the router and methods supported to connect with it. Is it normally possible to login using your web browser? Are you trying to do just that with this ping application? In that case you would need the login-page html and extract the form information from that. If not, please post as much info about the router, how you try to login and everything else you can think of. Also, because the return data looks quite stange, could it be that the data is in another format that ASCII?
Espen Harlinn 30-Sep-11 13:24pm    
Good reply :)
carlos pin 30-Sep-11 13:27pm    
Espen help me please to find solution to my pb,,,plz
carlos pin 30-Sep-11 16:17pm    
Is it normally possible to login using your web browser? Yes i can login with my browser see here http://www7.0zz0.com/2011/09/30/20/138068654.png
but my question is about login with tcpclient class exemple the telnet
http://www6.0zz0.com/2011/09/25/09/809657530.png
and login to it, I tried with web browser and it work well and I want login with Tcpcient class, please help me...
You can see this tutoriel :

http://www.albahari.com/nutshell/ch14.aspx[^]

good like carlos,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900