有没有一种方法可以从Windows命令行检查特定端口的状态?我知道我可以使用netstat来检查所有端口,但netstat很慢,而查看特定的端口可能不是。


当前回答

在linux中: 要找到一个你可以使用的外国端口:

Netstat -anp |grep端口|awk '{print $5}' |grep端口

要查找您可能使用的本地端口:

Netstat -anp |grep端口|awk '{print $4}' |grep端口

其他回答

这是一个简单的解决方案的港口寻找…

在cmd:

netstat -na | find "8080"

在bash中:

netstat -na | grep "8080"

PowerShell:

netstat -na | Select-String "8080"

当我有问题与WAMP apache,我使用这段代码找到哪个程序正在使用端口80。

netstat -o -n -a | findstr 0.0:80

3068是PID,所以我可以从任务管理器中找到它并停止该进程。

这对你有帮助

netstat -atn | grep <port no>          # For tcp
netstat -aun | grep <port no>           # For udp
netstat -atun | grep <port no>          # For both

Windows 8用户:打开命令提示符,输入netstat -an | find "your port number",输入。

如果回复是LISTENING,那么端口正在使用中,否则它是空闲的。

如其他地方所述:使用netstat,使用适当的开关,然后使用find[str]过滤结果

最基本的:

netstat -an | find ":N"

or

netstat -a -n | find ":N"

要找到一个你可以使用的外国端口:

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

要查找您可能使用的本地端口:

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

其中N为您感兴趣的端口号。

-n确保所有端口都是数字,即不返回转换为服务名称的端口。

-a将确保你搜索所有的连接(TCP, UDP,监听…)

在find字符串中,必须包含冒号作为端口限定符,否则该数字可能匹配本地地址或外部地址。

您可以根据需要使用其他netstat开关进一步缩小搜索范围…

进一步阅读(^0^)

netstat /?

find /?

findstr /?