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#如何检测网络端口连接的状态的更多相关文章
- android 检测网络是否连接,或者GPS是否可用
很多android程序在打开时,检测网络是否连接,或者GPS是否可用: 1.网络是否连接(包括Wifi和移动网络) // 是否有可用网络 private boolean isNetworkConnec ...
- [Xcode 实际操作]八、网络与多线程-(1)使用Reachability类库检测网络的连接状态
目录:[Swift]Xcode实际操作 本文将演示如何使用Reachability网络状态检测库,检测设备的网络连接状态. 需要下载一个开源的类库:[ashleymills/Reachability. ...
- 转载 iOS全局检测网络变化的实时状态
昨天浏览了cocoaChina,发现了一遍文章是优化Reachablity框架的出来的检测网络类,大家都知道这个Reachablity框架是用来检测网络变化的!但是也是有一点bug,事实上,基于此 ...
- 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 ...
- iOS开发 - Swift实现检测网络连接状态及网络类型
一.前言 在移动开发中,检测网络的连接状态尤其检测网络的类型尤为重要.本文将介绍在iOS开发中,如何使用Swift检测网络连接状态及网络类型(移动网络.Wifi). 二.如何实现 Reachabili ...
- Linux 查看网卡流量、网络端口
查看网络流量 # 查看网卡流量 命令:sar -n DEV 1 10 注:每1秒 显示 1次 显示 10次 平均时间: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcm ...
- Android 检测网络连接状态
Android连接网络的时候,并不是每次都能连接到网络,因此在程序启动中需要对网络的状态进行判断,如果没有网络则提醒用户进行设置. 首先,要判断网络状态,需要有相应的权限,下面为权限代码(Androi ...
- iOS检测网络连接状态
官方Demo下载地址:https://developer.apple.com/library/ios/samplecode/Reachability/Reachability.zip 将Reachab ...
- Delphi检测网络连接状态
有时候,我们做一些小软件就需要检测网络连接状态,比如想给你的软件加上类似QQ那样的系统消息,可是像我这样的穷人肯定是买不起服务器了,那我们只好另想办法,可以读取网页然后用浏览器显示,这个时候就需要判断 ...
随机推荐
- LUOGU P4281 [AHOI2008]紧急集合 / 聚会 (lca)
传送门 解题思路 可以通过手玩或打表发现,其实要选的点一定是他们三个两两配对后其中一对的$lca$上,那么就直接算出来所有的$lca$,比较大小就行了. #include<iostream> ...
- 染色(dye)
染色(dye) Description Serene 和 Achen 在玩染色游戏.Serene 和 Achen 站在一个 n 个点 m 条边的无向连通图中,在第 i 次玩染色游戏时,Serene 在 ...
- form表单简易注册登陆
注册页面: html <form action="updata.php" method="post" id="text_form"&g ...
- linux mint & ubuntu 安装QQ国际版
ubuntu安装QQ相对简单 下载qq国际版deb文件,直接安装即可. 下载地址: http://pan.baidu.com/s/1hqmYzlU 下面就重点说一下linux mint 安装qq. 1 ...
- Java常用英语汇总(面试必备)
Java常用英语汇总(面试必备) abstract (关键字) 抽象 ['.bstr.kt] access vt.访问,存 ...
- mysql数据库创建数据库创建用户授权
Liunx下登录数据库 >mysql -u 用户名 -p 创建myblog用户,本地登录,口令是myblog create user 'myblog'@'localhost' identifie ...
- docker中使用源码方式搭建SRS流媒体服务
一.背景 搭建流媒体服务的方式一般会采用nginx+rtmp和srs服务两种,前者是nginx加上插件所用,而后者是专门为了为了流媒体而生,在这一节中我们将从头搭建srs流媒体服务 二. 运行环境 为 ...
- mysql下突然丢失权限
mysql Can't read dir of 今天打开mysql数据库突然报了这个错误 查后发现是表没权限,进行了mysql的data目录权限修改 1.show global variables ...
- 解决使用mybatis模糊查询为空的问题
解决方法: 在数据库配置的url后添加?useUnicode=true&characterEncoding=utf-8 参考: https://blog.csdn.net/IT_private ...
- python 解决抓取网页中的中文显示乱码问题
关于爬虫乱码有很多各式各样的问题,这里不仅是中文乱码,编码转换.还包括一些如日文.韩文 .俄文.藏文之类的乱码处理,因为解决方式是一致的,故在此统一说明. 网络爬虫出现乱码的原因 源网页编码和爬取下来 ...