C# 如何在C中确定Windows进程使用的tcp端口#

C# 如何在C中确定Windows进程使用的tcp端口#,c#,tcp,C#,Tcp,是否有一个托管类/方法可以提供特定Windows进程使用的TCP端口号 我正在寻找与以下命令行相当的.NET命令: netstat -ano |find /i "listening" 请参见此处,以获取C#中netstat的等价物: 更新:链接已断开,但这里有一个等价项: 更新:原始页面已在存档。除PID外,请查看以下内容: IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties(); IPEndP

是否有一个托管类/方法可以提供特定Windows进程使用的TCP端口号

我正在寻找与以下命令行相当的.NET命令:

netstat -ano |find /i "listening"

请参见此处,以获取C#中netstat的等价物:

更新:链接已断开,但这里有一个等价项:


更新:原始页面已在存档。

除PID外,请查看以下内容:

IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();

IPEndPoint[] endPoints = ipProperties.GetActiveTcpListeners();
TcpConnectionInformation[] tcpConnections = 
    ipProperties.GetActiveTcpConnections();

foreach (TcpConnectionInformation info in tcpConnections)
{
    Console.WriteLine("Local: {0}:{1}\nRemote: {2}:{3}\nState: {4}\n", 
        info.LocalEndPoint.Address, info.LocalEndPoint.Port,
        info.RemoteEndPoint.Address, info.RemoteEndPoint.Port,
        info.State.ToString());
}
Console.ReadLine();
资料来源:


更多的研究带来了这一点:。这将使用P/Invoke调用
GetExtendedTcpTable
,并使用与
netstat

相同的结构来获取“构建您自己的netstat”的PID?链接。具有工作链接:@EddPorter更新:未找到页面:(