C#检测远程计算机端口是否打开的方法
作者:chongq 时间:2023-12-11 08:55:31
本文实例讲述了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#,检测,端口
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
小白2分钟学会Visual Studio如何将引用包打包到NuGet上
2022-01-14 10:25:53
![](https://img.aspxhome.com/file/2023/9/70439_0s.jpg)
Android 读取资源文件实例详解
2022-08-28 13:31:17
C#浏览器提示跨域问题解决方案
2023-08-30 17:37:28
![](https://img.aspxhome.com/file/2023/0/108930_0s.png)
Java中Lambda表达式的使用详解
2022-01-02 04:52:16
java高并发之线程的基本操作详解
2023-12-04 13:35:25
![](https://img.aspxhome.com/file/2023/5/108175_0s.jpg)
C#中的multipart/form-data提交文件和参数
2021-09-26 09:40:19
学生视角看Java 面向对象的继承本质
2022-04-23 21:51:10
![](https://img.aspxhome.com/file/2023/0/59740_0s.png)
Java 遍历取出Map集合key-value数据的4种方法
2022-02-03 02:48:59
![](https://img.aspxhome.com/file/2023/0/71640_0s.png)
利用POI生成EXCEL文件的方法实例
2023-11-23 21:44:14
![](https://img.aspxhome.com/file/2023/3/59723_0s.png)
SpringBoot使用Kaptcha实现验证码的生成与验证功能
2022-11-30 15:57:44
![](https://img.aspxhome.com/file/2023/7/66977_0s.png)
Java中多媒体文件上传及页面回显的操作代码
2021-11-21 09:45:31
![](https://img.aspxhome.com/file/2023/2/66202_0s.png)
深入理解Java序列化与反序列化
2023-01-24 00:27:53
![](https://img.aspxhome.com/file/2023/2/79182_0s.png)
JavaWeb实现简单文件上传功能
2022-11-19 04:15:41
![](https://img.aspxhome.com/file/2023/1/86791_0s.jpg)
Java实现Redis的集合(set)命令操作
2022-05-08 11:07:03
![](https://img.aspxhome.com/file/2023/4/61954_0s.jpg)
java虚拟机原理:类加载过程详解
2023-08-09 11:35:37
MyBatis ofType和javaType的区别说明
2021-09-10 22:56:43
Android使用CountDownTimer模拟短信验证倒计时
2022-10-24 18:00:28
![](https://img.aspxhome.com/file/2023/3/123243_0s.gif)
java图形界面之布局设计
2021-11-10 16:07:40
java二叉查找树的实现代码
2022-08-12 02:36:43
c#实现16进制和字符串之间转换的代码
2023-07-22 08:28:09