• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

C#检测远程计算机端口是否打开

OC/C/C++ 水墨上仙 2697次浏览

这段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#检测远程计算机端口是否打开
喜欢 (0)
加载中……