telnet 求救,高分。在线等待!急!!!
slin 2004-06-13 10:28:17 请问如何在建立连接后向主机发送用户名和密码?
小弟对telnet的rfc不是很懂,我知道不能直接发送用户名和密码,要用telnet的命令,如IAC,DO,WILL等。
代码如下:
(注:要实现的功能是telnet到一台Unix主机上查看有哪些用户登陆了。)
int port = 23;
string server="192.168.0.2";
string user="abc"+"\r\n";
string passwd="abc<>hg"+"\r\n";
string command="who"+"\r\n";
TcpClient client = new TcpClient(server, port);
NetworkStream stream = client.GetStream();
byte[] szData = System.Text.Encoding.ASCII.GetBytes(user.ToCharArray());
stream.Write(szData,0,szData.Length);
szData = System.Text.Encoding.ASCII.GetBytes(passwd.ToCharArray());
stream.Write(szData,0,szData.Length);
szData = System.Text.Encoding.ASCII.GetBytes(command.ToCharArray());
stream.Write(szData,0,szData.Length);
byte[] bdata = new Byte[client.ReceiveBufferSize];
int bytes = stream.Read(bdata, 0, bdata.Length);
string tmp;
tmp= System.Text.Encoding.ASCII.GetString(bdata, 0, bytes);