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


当前回答

如其他地方所述:使用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 /?

其他回答

它会给你一个特定IP上所有活动的套接字:

netstat -an | find "172.20.1.166"
netstat -a -n | find /c "10.240.199.9:8080"

它会告诉你在特定IP和端口上活动的套接字的数量(服务器端口号)

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

在cmd:

netstat -na | find "8080"

在bash中:

netstat -na | grep "8080"

PowerShell:

netstat -na | Select-String "8080"

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

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

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

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

我使用:

netstat –aon | find "<port number>"

其中o表示进程ID。 现在你可以对进程ID做任何事情。 要终止进程,例如,使用:

taskkill /F /pid <process ID>