The example in this article describes how C # detects whether a remote computer port is open. Share to everyone for your reference. The specific analysis is as follows:
This C # code is used to detect whether port 3389 of the remote computer is processing open, and you can set other ports according to the actual needs
Using system;using system.collections.generic;using system.text;using system.net.networkinformation;namespace test{ Class Program { static void Main (string[] args) { gettcpconnections (); } public static void Gettcpconnections () { Ipglobalproperties properties = Ipglobalproperties.getipglobalproperties (); tcpconnectioninformation[] Connections = properties. Getactivetcpconnections (); foreach (Tcpconnectioninformation t in connections) { Console.Write ("Local endpoint: {0}", T. Localendpoint.tostring ()); Console.Write ("Remote endpoint: {0}", t.remoteendpoint.tostring ()); Console.WriteLine ("{0}", t.state); } Console.WriteLine (); Console.ReadLine ();}}}
The results of the operation are as follows:
Local endpoint:127.0.0.1:1025 remote endpoint:127.0.0.1:1026 establishedlocal endpoint:127.0.0.1:1026 remote Endpoint : 127.0.0.1:1025 establishedlocal endpoint:127.0.0.1:1028 Remote endpoint:127.0.0.1:16992 CloseWaitLocal endpoint: 127.0.0.1:1110 remote endpoint:127.0.0.1:4900 establishedlocal endpoint:127.0.0.1:2754 remote endpoint: 127.0.0.1:1110 closewaitlocal endpoint:127.0.0.1:2762 Remote endpoint:127.0.0.1:1110 closewaitlocal endpoint: 127.0.0.1:2773 remote endpoint:127.0.0.1:1110 closewaitlocal endpoint:127.0.0.1:2913 remote endpoint:127.0.0.1:1110 closewaitlocal endpoint:127.0.0.1:3014 remote endpoint:127.0.0.1:1110 closewaitlocal endpoint:127.0.0.1:3531 remote endpoint:127.0.0.1:1110 closewaitlocal endpoint:127.0.0.1:4012 Remote endpoint:127.0.0.1:1110 CloseWaitLocal endpoint:127.0.0.1:4900 Remote endpoint:127.0.0.1:1110 established
I hope this article is helpful to everyone's C # programming.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
C # method for detecting whether a remote computer port is open
This address: http://www.paobuke.com/develop/c-develop/pbk23100.html
Related Content C # programming call Cards.dll Implementing a graphical licensing feature example of three C # implementations of array inversion Mode C # Four basic data Types C #,. Three ways to convert a string (string) format to a datetime type in net
C # Read the system font color and size method in C #, ASP. NET Universal Extension Tool class typeparsec# for file read, write, create, copy, move, delete dotnetcharting usage examples in C #
C # method for detecting whether a remote computer port is open