端口连接数:
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
版权声明:本文为博主原创文章,转载请附上博文链接!
原文地址:https://www.cnblogs.com/lonelyxmas/p/10878858.html
时间: 2024-10-17 15:45:21