原文: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#如何检测网络端口连接的状态的更多相关文章

  1. android 检测网络是否连接,或者GPS是否可用

    很多android程序在打开时,检测网络是否连接,或者GPS是否可用: 1.网络是否连接(包括Wifi和移动网络) // 是否有可用网络 private boolean isNetworkConnec ...

  2. [Xcode 实际操作]八、网络与多线程-(1)使用Reachability类库检测网络的连接状态

    目录:[Swift]Xcode实际操作 本文将演示如何使用Reachability网络状态检测库,检测设备的网络连接状态. 需要下载一个开源的类库:[ashleymills/Reachability. ...

  3. 转载 iOS全局检测网络变化的实时状态

      昨天浏览了cocoaChina,发现了一遍文章是优化Reachablity框架的出来的检测网络类,大家都知道这个Reachablity框架是用来检测网络变化的!但是也是有一点bug,事实上,基于此 ...

  4. win平台下, 检测网络是否连接最好的办法

    [Delphi]检查URL是否有效的函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 function CheckUr ...

  5. iOS开发 - Swift实现检测网络连接状态及网络类型

    一.前言 在移动开发中,检测网络的连接状态尤其检测网络的类型尤为重要.本文将介绍在iOS开发中,如何使用Swift检测网络连接状态及网络类型(移动网络.Wifi). 二.如何实现 Reachabili ...

  6. Linux 查看网卡流量、网络端口

    查看网络流量 # 查看网卡流量 命令:sar -n DEV 1 10 注:每1秒 显示 1次 显示 10次 平均时间: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcm ...

  7. Android 检测网络连接状态

    Android连接网络的时候,并不是每次都能连接到网络,因此在程序启动中需要对网络的状态进行判断,如果没有网络则提醒用户进行设置. 首先,要判断网络状态,需要有相应的权限,下面为权限代码(Androi ...

  8. iOS检测网络连接状态

    官方Demo下载地址:https://developer.apple.com/library/ios/samplecode/Reachability/Reachability.zip 将Reachab ...

  9. Delphi检测网络连接状态

    有时候,我们做一些小软件就需要检测网络连接状态,比如想给你的软件加上类似QQ那样的系统消息,可是像我这样的穷人肯定是买不起服务器了,那我们只好另想办法,可以读取网页然后用浏览器显示,这个时候就需要判断 ...

随机推荐

  1. shell与crontab定时器的结合

    crond服务 以守护进程方式在无需人工干预的情况下来处理一些列的作业指令与服务 查看服务状态 systemctl status cron.service 停止服务 systemctl stop cr ...

  2. Axure中表格使用的技巧

    对于新手来说,用Axure做一个表格是一件麻烦的事情.本文教你如何快速学会Axure表格的基础应用. (1)Axure制作基本表格的使用 可以使用“线框图”中的“表格”控件来制作一些简单的表格,同时A ...

  3. RQNOJ--160 竞赛真理(01背包)

    题目http://www.rqnoj.cn/problem/160 分析:这是一个01背包问题,对于每一道题目,都有两个选择"做"或者"不做". 但是唯一不同的 ...

  4. 8种nosql数据库对比

    1. CouchDB 所用语言: Erlang 特点:DB一致性,易于使用 使用许可: Apache 协议: HTTP/REST 双向数据复制, 持续进行或临时处理, 处理时带冲突检查, 因此,采用的 ...

  5. bzoj4574:Zjoi2016线段树 dp

    传送门 题解传送门 //Achen #include<algorithm> #include<iostream> #include<cstring> #includ ...

  6. vue.js_06_vue.js的自定义指令和自定义键盘修饰符

    1.全局的自定义指令 实现:当页面刷新时,光标聚焦到搜索框中 <label> 搜索: <input type="text" class="form-co ...

  7. mysql函数替换域名

    UPDATE `pigcms_product` SET info = REPLACE ( info, 'oto.mph88.com', 'www.10000fk.net' ) ;

  8. tmux连接时多个显示器分别显示不同的窗口大小

      如果两个电脑连接同一个tmux,但是他们各自的显示器大小不同,那么就会在一个显示器部分会显示灰色区.在tmux里面有个设置可以更改,在tmux里面输入命令 tmux set-window-opti ...

  9. hdu 1171 (背包或者母函数问题)

    Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. Bu ...

  10. Python爬虫笔记【一】模拟用户访问之表单处理(3)

    学习的课本为<python网络数据采集>,大部分代码来此此书. 大多数网页表单都是由一些HTML 字段.一个提交按钮.一个在表单处理完之后跳转的“执行结果”(表单属性action 的值)页 ...