手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#检测远程计算机端口是否打开的方法
C#检测远程计算机端口是否打开的方法
摘要:本文实例讲述了C#检测远程计算机端口是否打开的方法。分享给大家供大家参考。具体分析如下:这段C#代码用于检测远程计算机的3389端口是否处理...

本文实例讲述了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#程序设计有所帮助。

【C#检测远程计算机端口是否打开的方法】相关文章:

C#开发之Socket网络编程TCP/IP层次模型、端口及报文等探讨

C# 屏蔽关键字的实现方法

C# 鼠标穿透窗体功能的实现方法

C#计算代码执行时间的方法

C#几种截取字符串的方法小结

c# winform取消右上角关闭按钮的实现方法

C# 正则判断一个数字的格式是否有逗号的代码

C# 运用params修饰符来实现变长参数传递的方法

C# 获取打印机当前状态的方法

C# 如何判断两个文件内容是否相同的方法

精品推荐
分类导航