c# 获取端口的连接数,网站的连接数
2024-10-18 07:27:17
端口连接数:
public static int PortTcpConnection(int port)
{
IPGlobalProperties properti = IPGlobalProperties.GetIPGlobalProperties();
var tcps = properti.GetActiveTcpConnections().ToList(); var list = tcps.Where(f => f.LocalEndPoint.Port == port); var iplist = list.GroupBy(f => f.RemoteEndPoint.Address);
return iplist.Count();
}
网站连接数:
public List<WebSite> ListSite()
{
List<WebSite> list = new List<WebSite>();
using (ServerManager sm = new ServerManager())
{
foreach (var s in sm.Sites)
{
WebSite site = new WebSite();
site.ID = s.Id;
site.SiteName = s.Name;
site.ApplicationPoolName = s.Applications["/"].ApplicationPoolName;
site.PhysicalPath = s.Applications["/"].VirtualDirectories["/"].PhysicalPath;
site.State = s.State.ToString(); //System.Management.ManagementObject o = new ManagementObject("Win32_PerfFormattedData_W3SVC_WebService.Name='" + s.Name + "'");
//site.CurrentConnections = int.Parse(o.Properties["CurrentConnections"].Value.ToString());这个太慢 int tcps = ;
foreach (var tmp in s.Bindings)
{
WebSite.Bind bind = new WebSite.Bind();
bind.IP = tmp.EndPoint.Address.ToString();
bind.Port = tmp.EndPoint.Port;
bind.Host = tmp.Host;
tcps += Util.SystemInfo.PortTcpConnection(bind.Port);
site.BindList.Add(bind);
}
site.CurrentConnections = tcps;//当前连接数
list.Add(site);
}
}
return list;
}
---------------------
原文:https://blog.csdn.net/wyljz/article/details/79207507
版权声明:本文为博主原创文章,转载请附上博文链接!
最新文章
- java开发环境的主题色的变化
- AngularJS的学习--TodoMVC的分析
- Sublime Text 2 一些常用的快捷键
- SPOJ 10628 求树上的某条路径上第k小的点
- ZOJ 1078 Palindrom Numbers
- 使用VS2013调试FluorineFx程序
- Android Activity的切换动画
- Go与GUI——GO语言的图形界面Walk
- apache的一些基本配置
- Bone Collector(01背包+记忆化搜索)
- 简要解析XMPP框架及iOS-Objective-C的使用
- CentOS 6.4 安装setuptools 和 pip
- 记 suds 模块循环依赖的坑-RuntimeError: maximum recursion depth exceeded
- HI3531的DDR3配置流程
- 【数据结构】赫夫曼树的实现和模拟压缩(C++)
- Java学习从菜鸟变大鸟之二 输入输出流(IO)
- 文本离散表示(二):新闻语料的one-hot编码
- Chrome - JavaScript调试技巧总结(浏览器调试JS)
- PHP 3 函数
- [ 原创 ] centos安装tomcat,启动成功 无法访问
热门文章
- C++ 11 创建和使用共享 weak_ptr
- Git - git clone - 将远端仓库克隆拷贝到本地
- jsp用el表达式获取后台传来的值,或者获取session中的值
- Windows系统XAMPP安装Moodle教程
- AES 加密与解密
- AngularJS学习之旅—AngularJS Scope作用域(五)
- 能ping通虚拟机,但snmp报文 Destination unreachable(Host administratively prohibited
- 5.3Python数据处理篇之Sympy系列(三)---简化操作
- 虚拟机硬盘vmdk压缩瘦身并挂载到VirtualBox
- Java list 转字符串并加入分隔符的方法