windows 查看特定端口的命令行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12010631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Command line for looking at specific port
提问by user1580018
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.
有没有办法从 Windows 命令行检查特定端口的状态?我知道我可以使用 netstat 来检查所有端口,但 netstat 很慢并且查看特定端口可能不是。
回答by Md. Naushad Alam
Here is the easy solutionof port finding...
这是端口查找的简单解决方案......
In cmd:
在 cmd 中:
netstat -na | find "8080"
In bash:
在 bash 中:
netstat -na | grep "8080"
In PowerShell:
在 PowerShell 中:
netstat -na | Select-String "8080"
回答by Rivasa
You can use the netstat
combined with the -np
flags and a pipe to the find
or findstr
commands.
您可以netstat
将 与-np
标志和管道结合使用到find
orfindstr
命令。
Basic Usage is as such:
基本用法如下:
netstat -np <protocol> | find "port #"
So for example to check port 80 on TCP, you can do this: netstat -np TCP | find "80"
Which ends up giving the following kind of output:
因此,例如要检查 TCP 上的端口 80,您可以执行以下操作:netstat -np TCP | find "80"
最终给出以下类型的输出:
TCP 192.168.0.105:50466 64.34.119.101:80 ESTABLISHED
TCP 192.168.0.105:50496 64.34.119.101:80 ESTABLISHED
As you can see, this only shows the connections on port 80 for the TCP protocol.
如您所见,这仅显示了 TCP 协议在端口 80 上的连接。
回答by Himadri Pant
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:
这里 o 代表进程 ID。现在您可以使用进程 ID 执行任何操作。要终止进程,例如,使用:
taskkill /F /pid <process ID>
回答by Mohsen Safari
when I have problem with WAMP apache , I use this code for find which program is using port 80.
当我遇到 WAMP apache 问题时,我使用此代码查找哪个程序正在使用端口 80。
netstat -o -n -a | findstr 0.0:80
3068
is PID, so I can find it from task manager and stop that process.
3068
是PID,所以我可以从任务管理器中找到它并停止该进程。
回答by EndUzr
As noted elsewhere: use netstat, with appropriate switches, and then filter the results with find[str]
如别处所述:使用 netstat 和适当的开关,然后使用 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 Nis the port number you are interested in.
其中N是您感兴趣的端口号。
-n
ensures all ports will be numerical, i.e. not returned as translated to service names.
-n
确保所有端口都是数字,即不返回转换为服务名称。
-a
will ensure you search all connections (TCP, UDP, listening...)
-a
将确保您搜索所有连接(TCP、UDP、侦听...)
In the find
string you must include the colon, as the port qualifier, otherwise the number may match either local or foreign addresses.
在find
字符串中,您必须包含冒号作为端口限定符,否则该数字可能与本地或外国地址匹配。
You can further narrow narrow the search using other netstat switches as necessary...
您可以根据需要使用其他 netstat 开关进一步缩小搜索范围...
Further reading (^0^)
进一步阅读 (^0^)
netstat /?
find /?
findstr /?
回答by Uday Singh
netstat -a -n | find /c "10.240.199.9:8080"
it will give you number of sockets active on a specific IP and port(Server port number)
它将为您提供特定 IP 和端口(服务器端口号)上活动的套接字数
回答by Pratik Roy
For Windows 8 User : Open Command Prompt, type netstat -an | find "your port number", enter .
对于 Windows 8 用户:打开命令提示符,键入netstat -an | 找到“你的端口号”,输入。
If reply comes like LISTENINGthen the port is in use, else it is free .
如果回复像LISTENING一样,那么端口正在使用中,否则它是 free 。
回答by shawn
To improve upon @EndUzr's response:
改进@EndUzr 的回复:
To find a foreign port (IPv4 or IPv6) you can use:
要查找外部端口(IPv4 或 IPv6),您可以使用:
netstat -an | findstr /r /c:":N [^:]*$"
To find a local port (IPv4 or IPv6) you can use:
要查找本地端口(IPv4 或 IPv6),您可以使用:
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.
其中 N 是您感兴趣的端口号。“/r”开关告诉它将它作为正则表达式处理。"/c" 开关允许 findstr 在搜索字符串中包含空格,而不是将空格视为搜索字符串分隔符。这个增加的空间可以防止更长的端口被滥用——例如,“:80”与“:8080”和其他端口修改问题。
To list remote connections to the local RDP server, for example:
要列出到本地 RDP 服务器的远程连接,例如:
netstat -an | findstr /r /c:":3389 *[^ ]*:[^ ]*"
Or to see who is touching your DNS:
或者查看谁在接触您的 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:
如果您想排除本地端口,您可以使用一系列带有 "/v" 的异常并使用反斜杠转义字符:
netstat -an | findstr /v "0.0.0.0 127.0.0.1 \[::\] \[::1\] \*\:\*" | findstr /r /c:":80 *[^ ]*:[^ ]*"
回答by subodhkarwa
For port 80, the command would be : netstat -an | find "80" For port n, the command would be : netstat -an | find "n"
对于端口 80,命令将是:netstat -an | find "80" 对于端口 n,命令是:netstat -an | 找到“n”
Here, netstat is the instruction to your machine
这里,netstat 是你机器的指令
-a : Displays all connections and listening ports -n : Displays all address and instructions in numerical format (This is required because output from -a can contain machine names)
-a :显示所有连接和监听端口 -n :以数字格式显示所有地址和指令(这是必需的,因为 -a 的输出可以包含机器名称)
Then, a find command to "Pattern Match" the output of previous command.
然后,使用 find 命令“模式匹配”上一个命令的输出。
回答by jobin
This will help you
这会帮助你
netstat -atn | grep <port no> # For tcp
netstat -aun | grep <port no> # For udp
netstat -atun | grep <port no> # For both