c# 获取端口的连接数,网站的连接数
Posted lonelyxmas
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c# 获取端口的连接数,网站的连接数相关的知识,希望对你有一定的参考价值。
原文:c# 获取端口的连接数,网站的连接数端口连接数:
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 = 0; 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
版权声明:本文为博主原创文章,转载请附上博文链接!
以上是关于c# 获取端口的连接数,网站的连接数的主要内容,如果未能解决你的问题,请参考以下文章