Click here to Skip to main content
Rate this: bad
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 and port 23, the username="admin" and password="admin" also, and the code used is :
TcpClient tcpclient = new TcpClient();
                tcpclient.Connect("", 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);
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
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.
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
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 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.
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Check this Link if it helps out[^]
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 Maciej Los 495
1 Sergey Alexandrovich Kryukov 469
2 OriginalGriff 360
3 Sascha Lefévre 255
4 Abhinav S 250
0 Sergey Alexandrovich Kryukov 10,102
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 2 Oct 2011
Copyright © CodeProject, 1999-2015
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