I want to list all the http active connections from the host, I'm using the code below, which lists any tcp connections, but I want to find specifically the http ones from this tcp list.
我想列出来自主机的所有http活动连接,我正在使用下面的代码,其中列出了所有tcp连接,但我想特别找到来自此tcp列表的http连接。
Console.WriteLine("Active TCP Connections");
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
foreach (TcpConnectionInformation c in connections)
{
Console.WriteLine("{0} <==> {1}",
c.LocalEndPoint.ToString(),
c.RemoteEndPoint.ToString());
}
2 个解决方案
#1
3
Port 80
is the standard HTTP port, and port 443
is the standard HTTPS port. You might want to filter for both.
端口80是标准HTTP端口,端口443是标准HTTPS端口。您可能希望对两者进行过滤。
Change your foreach
loop to the following:
将foreach循环更改为以下内容:
foreach (TcpConnectionInformation c in connections)
{
if ((c.RemoteEndPoint.Port == 80) || (c.RemoteEndPoint.Port == 443))
{
Console.WriteLine("{0} <==> {1}:{2}",
c.LocalEndPoint.ToString(),
c.RemoteEndPoint.ToString(),
c.RemoteEndPoint.Port);
}
}
#2
0
Just because a TCP port is open doesn't mean only HTTP traffic will be traveling across it. Unless you have some other criteria to use in identifying a TCP connection as an "HTTP" connection, filtering for port 80 is probably as close as you're going to get.
仅仅因为TCP端口是打开的并不仅仅意味着HTTP流量将通过它传输。除非您有一些其他标准用于将TCP连接标识为“HTTP”连接,否则对端口80的过滤可能就像您将获得的那样接近。
#1
3
Port 80
is the standard HTTP port, and port 443
is the standard HTTPS port. You might want to filter for both.
端口80是标准HTTP端口,端口443是标准HTTPS端口。您可能希望对两者进行过滤。
Change your foreach
loop to the following:
将foreach循环更改为以下内容:
foreach (TcpConnectionInformation c in connections)
{
if ((c.RemoteEndPoint.Port == 80) || (c.RemoteEndPoint.Port == 443))
{
Console.WriteLine("{0} <==> {1}:{2}",
c.LocalEndPoint.ToString(),
c.RemoteEndPoint.ToString(),
c.RemoteEndPoint.Port);
}
}
#2
0
Just because a TCP port is open doesn't mean only HTTP traffic will be traveling across it. Unless you have some other criteria to use in identifying a TCP connection as an "HTTP" connection, filtering for port 80 is probably as close as you're going to get.
仅仅因为TCP端口是打开的并不仅仅意味着HTTP流量将通过它传输。除非您有一些其他标准用于将TCP连接标识为“HTTP”连接,否则对端口80的过滤可能就像您将获得的那样接近。