简体   繁体   中英

tcp connection to router how to communicate? (Telnet Client)

I am trying to build a program that will connect to an IP address (preferably that of a router) to a specific port (mainly 80) and will try to authenticate and then go on with further actions.

I started without knowing how to communicate with the router/server so i did this:

while (tcpSocket.Available > 0)
{
  int input = tcpSocket.GetStream().ReadByte();

But it always gets a tcpSocket.Available = 0 So then i found out that i have to send a specific cmd for it to talk to me. http://msdn.microsoft.com/en-us/library/cc247846.aspx

and made this

var client = new TcpClient(ip, port);
var data = Encoding.GetEncoding(1252).GetBytes(cmd);
var stm = client.GetStream();
stm.Write(data, 0, data.Length);

Now I dont understand how to format the cmds the cmd based on this http://www.ietf.org/rfc/rfc2941.txt Would be 37 - 1?

Thank you for reading PS dont know if i should point this to SuperUser or ServerFault

I think you need to go back to simpler questions and investigations.

First: What protocol is actually running on the server you are connecting to? Port 80 suggests it is HTTP (port 80 is typically reserved for HTTP). Telnet typically runs on port 23.
If it is HTTP you need to follow the protocol defined in RFC 2616 (with the authentication options defined in RFC 2617).

Even simpler yet: connect to the server using PuTTY (or other preferred telnet client). What do you need to do in order to log in? If it is a telnet server then it will probably show a banner followed by a login prompt. You will type the username followed by return, then it will show you a password prompt. If it is a HTTP server then it will probably show you nothing at all, but type HTTP/1.0 (return) HEAD / (return) and you should see a HTTP message response. Whatever you need to do using PuTTY, your program will need to do exactly the same thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM