Command line for looking at specific port

2019-01-09 22:46发布

Is there a way to examine the status of a specific port from the Windows command line? I know I can use netstat to examine all ports but netstat is slow and looking at a specific port probably isn't.

11条回答
对你真心纯属浪费
2楼-- · 2019-01-09 23:03

I use:

netstat –aon | find "<port number>"

here o represents process ID. now you can do whatever with the process ID. To terminate the process, for e.g., use:

taskkill /F /pid <process ID>
查看更多
Summer. ? 凉城
3楼-- · 2019-01-09 23:03

As noted elsewhere: use netstat, with appropriate switches, and then filter the results with find[str]

Most basic:

netstat -an | find ":N"

or

netstat -a -n | find ":N"

To find a foreign port you could use:

netstat -an | findstr ":N[^:]*$"

To find a local port you might use:

netstat -an | findstr ":N.*:[^:]*$"

Where N is the port number you are interested in.

-n ensures all ports will be numerical, i.e. not returned as translated to service names.

-a will ensure you search all connections (TCP, UDP, listening...)

In the find string you must include the colon, as the port qualifier, otherwise the number may match either local or foreign addresses.

You can further narrow narrow the search using other netstat switches as necessary...

Further reading (^0^)

netstat /?

find /?

findstr /?
查看更多
家丑人穷心不美
4楼-- · 2019-01-09 23:08

To improve upon @EndUzr's response:

To find a foreign port (IPv4 or IPv6) you can use:

netstat -an | findstr /r /c:":N [^:]*$"

To find a local port (IPv4 or IPv6) you can use:

netstat -an | findstr /r /c:":N *[^ ]*:[^ ]* "

Where N is the port number you are interested in. The "/r" switch tells it to process it as regexp. The "/c" switch allows findstr to include spaces within search strings instead of treating a space as a search string delimiter. This added space prevents longer ports being mistreated - for example, ":80" vs ":8080" and other port munging issues.

To list remote connections to the local RDP server, for example:

netstat -an | findstr /r /c:":3389 *[^ ]*:[^ ]*"

Or to see who is touching your DNS:

netstat -an | findstr /r /c:":53 *[^ ]*:[^ ]*"

If you want to exclude local-only ports you can use a series of exceptions with "/v" and escape characters with a backslash:

netstat -an | findstr /v "0.0.0.0 127.0.0.1 \[::\] \[::1\] \*\:\*" | findstr /r /c:":80 *[^ ]*:[^ ]*"
查看更多
Evening l夕情丶
5楼-- · 2019-01-09 23:13

For Windows 8 User : Open Command Prompt, type netstat -an | find "your port number" , enter .

If reply comes like LISTENING then the port is in use, else it is free .

查看更多
做个烂人
6楼-- · 2019-01-09 23:13

This command will show all the ports and their destination address:

netstat -f 
查看更多
登录 后发表回答