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);
...全文
99 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zedan 2004-06-13
  • 打赏
  • 举报
回复
up
greatsft 2004-06-13
  • 打赏
  • 举报
回复
可以直接用
Process类中的方法比如
Process p = new Process();

p.StartInfo.FileName = "cmd.exe";

p.StartInfo.UseShellExecute = false;

p.StartInfo.RedirectStandardInput = true;

p.StartInfo.RedirectStandardOutput = true;

p.StartInfo.RedirectStandardError = true;

p.StartInfo.CreateNoWindow = true;

p.Start();

p.StandardInput.WriteLine("telnet ...");//发送相关远程登陆命令

p.StandardInput.WriteLine("exit");
MessageBox.Show("发送成功!");

wish u good luck
Greatsft
CtrlT 2004-06-13
  • 打赏
  • 举报
回复
mark up!

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧