本文实例讲述了c#检测远程计算机端口是否打开的方法。分享给大家供大家参考。具体分析如下:
这段c#代码用于检测远程计算机的3389端口是否处理打开状态,可以根据实际需要设置其它端口
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(); } } }
运行结果如下:
local endpoint: 127.0.0.1:1025 remote endpoint: 127.0.0.1:1026 established local endpoint: 127.0.0.1:1026 remote endpoint: 127.0.0.1:1025 established local endpoint: 127.0.0.1:1028 remote endpoint: 127.0.0.1:16992 closewait local endpoint: 127.0.0.1:1110 remote endpoint: 127.0.0.1:4900 established local endpoint: 127.0.0.1:2754 remote endpoint: 127.0.0.1:1110 closewait local endpoint: 127.0.0.1:2762 remote endpoint: 127.0.0.1:1110 closewait local endpoint: 127.0.0.1:2773 remote endpoint: 127.0.0.1:1110 closewait local endpoint: 127.0.0.1:2913 remote endpoint: 127.0.0.1:1110 closewait local endpoint: 127.0.0.1:3014 remote endpoint: 127.0.0.1:1110 closewait local endpoint: 127.0.0.1:3531 remote endpoint: 127.0.0.1:1110 closewait local endpoint: 127.0.0.1:4012 remote endpoint: 127.0.0.1:1110 closewait local endpoint: 127.0.0.1:4900 remote endpoint: 127.0.0.1:1110 established
希望本文所述对大家的c#程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论