简体   繁体   English

TCP连接到路由器如何通讯? (Telnet客户端)

[英]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. 我正在尝试构建一个程序,该程序将连接到IP地址(最好是路由器的IP地址)到特定端口(主要是80),并将尝试进行身份验证,然后继续执行进一步的操作。

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. 但是它总是得到一个tcpSocket.Available = 0,所以我发现我必须发送一个特定的cmd才能与我交谈。 http://msdn.microsoft.com/en-us/library/cc247846.aspx 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? 现在我不明白如何基于此http://www.ietf.org/rfc/rfc2941.txt将cmd格式化为37-1?

Thank you for reading PS dont know if i should point this to SuperUser or ServerFault 感谢您阅读PS不知道我是否应该将此指向SuperUser或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). 端口80表示它是HTTP(端口80通常为HTTP保留)。 Telnet typically runs on port 23. Telnet通常在端口23上运行。
If it is HTTP you need to follow the protocol defined in RFC 2616 (with the authentication options defined in RFC 2617). 如果是HTTP,则需要遵循RFC 2616中定义的协议(以及RFC 2617中定义的身份验证选项)。

Even simpler yet: connect to the server using PuTTY (or other preferred telnet client). 甚至更简单:使用PuTTY(或其他首选的telnet客户端)连接到服务器。 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. 如果是telnet服务器,则可能会显示一个标语,后跟一个登录提示。 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. 如果它是HTTP服务器,那么它可能什么都不显示,但是键入HTTP/1.0 (返回) HEAD / (返回),您应该看到HTTP消息响应。 Whatever you need to do using PuTTY, your program will need to do exactly the same thing. 无论您需要使用PuTTY做什么,您的程序都需要做完全相同的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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