java 测试远程端口是否打开,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()

{

//code from http://www.75271.com/codes

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#检测远程计算机端口是否打开!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值