如何确定哪个进程正在侦听Windows上的TCP或UDP端口?


当前回答

使用Windows的默认shell(PowerShell),不使用外部应用程序

对于使用PowerShell的用户,请尝试Get NetworkStatistics:

> Get-NetworkStatistics | where Localport -eq 8000


ComputerName  : DESKTOP-JL59SC6
Protocol      : TCP
LocalAddress  : 0.0.0.0
LocalPort     : 8000
RemoteAddress : 0.0.0.0
RemotePort    : 0
State         : LISTENING
ProcessName   : node
PID           : 11552

其他回答

在编程上,您需要iphlpapi.h中的东西,例如GetTcpTable2()。像MIB_TCP6ROW2这样的结构包含所有者PID。

查找使用端口8000的pid

netstat -aon | findstr '8000'

在窗口中终止该进程

taskkill /pid pid /f

其中pid是从first命令中获取的进程id

对于Windows:

netstat -aon | find /i "listening"

如果您想使用GUI工具来实现这一点,可以使用Sysinternals的TCPView。

对于Windows 10或Windows Server 2016上的PowerShell 5,运行Get-NetTCPConnection cmdlet。我想它应该也适用于较旧的Windows版本。

由于某种原因,Get-NetTCPConnection的默认输出不包含进程ID,这有点令人困惑。然而,您总是可以通过格式化输出来获得它。您要查找的属性是OwningProcess。

如果要查找在端口443上侦听的进程的ID,请运行以下命令:PS C:\>获取NetTCPConnection-LocalPort 443 |格式列表本地地址:::本地端口:443RemoteAddress:::远程端口:0状态:听应用设置:拥有流程:4572创建时间:2016年11月2日21:55:43卸载状态:InHost将输出格式化为具有您查找的财产的表:PS C:\>获取NetTCPConnection-LocalPort 443 |格式表-属性LocalAddress、LocalPort、State、OwningProcess本地地址本地端口状态拥有进程------------ --------- ----- -------------::443听45720.0.0.0 443听4572如果要查找进程的名称,请运行以下命令:PS C:\>获取进程-Id(获取NetTCPConnection-LocalPort 443)。拥有进程处理NPM(K)PM(K)WS(K)CPU Id SI进程名称------- ------ ----- ----- ------ -- -- -----------143 15 3448 11024 4572 0 VisualSVNS服务器