基于Sockets
没什么好说的,代码说明了所有
1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Linq;4usingSystem.Text;5usingSystem.Net.Sockets;6usingSystem.IO;78namespaceConsoleapplication19{10classPRogram11{12publicstaticNetworkStream stream;13publicstaticTcpClient tcpclient;14publicstaticstringip;15publicstaticintport;16staticvoidMain(string[] args)17{18Console.WriteLine("目标IP:");19ip =Console.ReadLine();20Console.WriteLine("目标Port:");21port =int.Parse(Console.ReadLine());2223Run();24}2526staticpublicvoidRun()27{28tcpclient =newTcpClient(ip, port);//连接服务器29stream = tcpclient.GetStream();//获取网络数据流对象30StreamWriter sw =newStreamWriter(stream);31StreamReader sr =newStreamReader(stream);32while(true)33{34//Read Echo35//Set ReadEcho Timeout36stream.ReadTimeout =10;37try38{39while(true)40{41charc = (char)sr.Read();42if(c <256)43{44if(c ==27)45{46while(sr.Read() !=109) { }47}48else49{50Console.Write(c);51}52}53}54}55catch56{5758}59//Send CMD60sw.Write("{0}\r\n", Console.ReadLine());61sw.Flush();62}63}6465}66}
TcpClient