C# 超級簡單的Telnet (TcpClient)用戶端

來源:互聯網
上載者:User

標籤:

基於Sockets

沒什麼好說的,代碼說明了所有

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Net.Sockets; 6 using System.IO; 7  8 namespace ConsoleApplication1 9 {10     class Program11     {12         public static NetworkStream stream;13         public static TcpClient tcpclient;14         public static string ip;15         public static  int port;16         static void Main(string[] args)17         {18             Console.WriteLine("目標IP:");19             ip = Console.ReadLine();20             Console.WriteLine("目標Port:");21             port =int.Parse(Console.ReadLine());22 23             Run();24         }25 26         static public void Run()27         {28             tcpclient = new TcpClient(ip, port);  // 串連伺服器29             stream = tcpclient.GetStream();   // 擷取網路資料流對象30             StreamWriter sw = new StreamWriter(stream);31             StreamReader sr = new StreamReader(stream);32             while (true)33             {34                 //Read Echo35                 //Set ReadEcho Timeout36                 stream.ReadTimeout = 10;37                 try38                 {39                     while (true)40                     {                        41                             char c = (char)sr.Read();42                             if (c < 256)43                             {44                                 if (c == 27)45                                 {46                                     while (sr.Read() != 109) { }47                                 }48                                 else49                                 {50                                     Console.Write(c);51                                 }52                             }53                     }54                 }55                 catch56                 {57                     58                 }59                 //Send CMD60                 sw.Write("{0}\r\n", Console.ReadLine());61                 sw.Flush();62             }63         }64 65     }66 }
TcpClient

 

C# 超級簡單的Telnet (TcpClient)用戶端

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.