一个TELNET类,不知是使用出错还是代码出错,求高人分析
近来在研究者telnet的应用,自己不会开发,所以上网找了一个类
类地址:http://www.cnblogs.com/yinchengliang/archive/2012/06/05/2536887.html
这个是自己的主函数
class Program
{
static void Main(string[] args)
{
Telnet p = new Telnet("192.168.220.128", 23, 300);
if (p.Connect() == false)
{
Console.WriteLine("连接失败");
Console.ReadKey();
Console.WriteLine(p.SessionLog);
Console.WriteLine(p.WorkingData);
return;
}
//等待指定字符返回后才执行下一命令
p.WaitFor("login:");
p.Send("administrator");
p.WaitFor("password:");
p.Send("chinagdn");
p.WaitFor(">");
Console.WriteLine(p.SessionLog);
p.Send("hlep");
p.Send("dir");
p.Send("dir");
Console.WriteLine(p.SessionLog);
Console.WriteLine(p.WorkingData);
Console.ReadKey();
}
}
o - open hostname [port] connect to hostname (default port 23).
q - quit exit telnet
set - set set options (type 'set ?' for a list)
sen - send send strings to server
st - status print status information
u - unset unset options (type 'unset ?' for a list)
?/h - help print help information