How can you find out which process is listening on

2018-12-31 04:17发布

How can you find out which process is listening on a port on Windows?

26条回答
爱死公子算了
2楼-- · 2018-12-31 05:03

For Windows, if you want to find stuff listening or connected to port 1234, execute the following at the cmd prompt:

netstat -na | find "1234"
查看更多
听够珍惜
3楼-- · 2018-12-31 05:04

Type in the command: netstat -aon | findstr :DESIRED_PORT_NUMBER

For example, if I want to find port 80: netstat -aon | findstr :80

This answer was originally posted in this thread.

查看更多
忆尘夕之涩
4楼-- · 2018-12-31 05:08

If you'd like to use a GUI tool to do this there's SysInternals TCPView.

查看更多
春风洒进眼中
5楼-- · 2018-12-31 05:10

The -b switch mentioned in most answers requires you to have administrative privileges on the machine. You don't really need elevated rights to get the process name!

Find the pid of the process running in the port number (e.g., 8080)

netstat -ano | findStr "8080"

Find the process name by pid

tasklist /fi "pid eq 2216"

find process by TCP/IP port

查看更多
ら面具成の殇う
6楼-- · 2018-12-31 05:10

Get PID and Image Name

Use only one command:

for /f "tokens=5" %a in ('netstat -aon ^| findstr 9000') do tasklist /FI "PID eq %a"

where 9000 should be replaced by your port number.

The output will contain something like this:

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
java.exe                      5312 Services                   0    130,768 K

Explanation:

  • it iterates through every line from the output of the following command:

    netstat -aon | findstr 9000
    
  • from every line, the PID (%a - the name is not important here) is extracted (PID is the 5th element in that line) and passed to the following command

    tasklist /FI "PID eq 5312"
    

If you want to skip the header and the return of the command prompt, you can use:

echo off & (for /f "tokens=5" %a in ('netstat -aon ^| findstr 9000') do tasklist /NH /FI "PID eq %a") & echo on

Output:

java.exe                      5312 Services                   0    130,768 K
查看更多
其实,你不懂
7楼-- · 2018-12-31 05:10

For those using Powershell, try 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
查看更多
登录 后发表回答