Click here to Skip to main content
15,886,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I'm trying to login (Authenticate) to my router 192.168.1.1 and port 23, the username="admin" and password="admin" also, 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
            {
                
            }


1-My router is lestening to 23 port,
2-I can login to my router with browser very well,

please help me to use NegotiateStream with Tcpclient in Asycrous methode,,,
Posted

You posted a simialr question yesterday:How to login automatically to my router ?[^]

1-My router is lestening to 23 port,
2-I can login to my router with browser very well

Seems to indicate that the router has a built-in web server - and that's common.

So you need to "talk" to it using the http protocol[^] - it will reply with HTML, that you need to parse.

E.F. Nijboer answer yesterday about using the HttpWebResponse class will solve your problem, but you probably need to read up on the topic - and that a lot of information.

[Update]
Telnet is another common protocol that can be used with many routers - here is a nice little implementation of a telnet client in c#:Quick tool : A minimalistic Telnet library[^]

Best regards
Espen Harlinn
 
Share this answer
 
v2
Comments
carlos pin 1-Oct-11 7:25am    
I read your answer, and I think your response is not appropriate to my problem, i haven't told about http protocol, my protocole is the same of telnet protocol, because I have to connect to my router 192.168.1.1 and send the username and password (login), and after I can send commands to my router...this is what i want,,,how can i do it?because always i'm coonecting to my router he ask me about the username and password,,,
Espen Harlinn 1-Oct-11 7:43am    
You didn't specify the the http protocol, but you told us that you where able to connect to the router using your browser - that's just another way to tell us that the router supports the http protocol. I've included a link to a nice telnet library in an update to my answer :)
Sergey Alexandrovich Kryukov 1-Oct-11 11:17am    
Good point, my 5.
--SA
Espen Harlinn 1-Oct-11 11:52am    
Thank you, Sergey!
Kim Togo 1-Oct-11 13:11pm    
My 5 for at good answer that will help OP to solve the problem :-)
Check this Link if it helps out

http://msdn.microsoft.com/en-us/library/ms145193.aspx[^]
 
Share this answer
 
Comments
carlos pin 1-Oct-11 14:40pm    
what can help me this link? maybe explain the TcpClient?

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