Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 C# C#4.0
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 1-Oct-11 1:58am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Comments
carlos pin at 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 at 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 :)
SAKryukov at 1-Oct-11 11:17am
   
Good point, my 5.
--SA
Espen Harlinn at 1-Oct-11 11:52am
   
Thank you, Sergey!
Kim Togo at 1-Oct-11 13:11pm
   
My 5 for at good answer that will help OP to solve the problem :-)
Espen Harlinn at 1-Oct-11 13:14pm
   
Thank you, Kim!
carlos pin at 1-Oct-11 14:39pm
   
I think my question is clear,,,
I am Italian and I do not speak English very well, and I'm sad not to find a solution for my problem (é_è), thank you friends
Bala Selvanayagam at 2-Oct-11 6:14am
   
not sure this can help you
http://www.codeproject.com/KB/IP/MinimalisticTelnet.aspx
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check this Link if it helps out
 
http://msdn.microsoft.com/en-us/library/ms145193.aspx[^]
  Permalink  
Comments
carlos pin at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 545
1 Kornfeld Eliyahu Peter 407
2 Maciej Los 369
3 DamithSL 221
4 OriginalGriff 218
0 OriginalGriff 6,383
1 DamithSL 4,879
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,056
4 Sergey Alexandrovich Kryukov 3,927


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 2 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100