折腾:
【未解决】Windows中查看哪个进程占用某端口号并杀掉该进程
期间,还是要先去搞清楚windows中netstat的命令的语法和功能含义。
才好去实现自己此处的目的
搞清楚哪个进程占用了此处的4242端口,导致后续启动zmq时才报错:
(venv) D:\dev\DevRoot\mitmdumpurlsaver\electron-python-example>pymitmdumpstartdist\mitmdumpStartApi\mitmdumpStartApi.exe 4242 Traceback (most recent call last): File "mitmdumpStartApi.py", line 137, in <module> File "mitmdumpStartApi.py", line 115, in main File "site-packages\zerorpc\socket.py", line 43, in bind File "site-packages\zerorpc\events.py", line 325, in bind File "zmq\backend\cython\socket.pyx", line 550, in zmq.backend.cython.socket.Socket.bind File "zmq\backend\cython\checkrc.pxd", line 25, in zmq.backend.cython.checkrc._check_rc zmq.error.ZMQError: Address in use [25128] Failed to execute script mitmdumpStartApi
总之,目的是:
找到上述zmq的进程,并杀掉。
windows netstat 查看端口
windows netstat port
windows netstat port be used
C:\Windows\system32>netstat -ano 活动连接 协议 本地地址 外部地址 状态 PID TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 1048 TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4 。。。 TCP 127.0.0.1:61909 127.0.0.1:61908 ESTABLISHED 22420 TCP 127.0.0.1:63342 0.0.0.0:0 LISTENING 8304 TCP 192.168.31.119:139 0.0.0.0:0 LISTENING 4 TCP 192.168.31.119:5786 0.0.0.0:0 LISTENING 22420 TCP 192.168.31.119:8081 192.168.31.172:34102 ESTABLISHED 18464 。。。 TCP 192.168.31.119:61969 183.57.48.56:443 CLOSE_WAIT 22420 TCP [::]:135 [::]:0 LISTENING 1048 TCP [::]:445 [::]:0 LISTENING 4 。。。 TCP [::1]:49856 [::]:0 LISTENING 7152 UDP 0.0.0.0:123 *:* 1268 。。。 UDP 192.168.31.119:57982 *:* 3084 UDP [::]:123 *:* 1268 UDP [::]:500 *:* 2520 。。。 UDP [::1]:57981 *:* 3084 UDP [fe80::d6f:942b:240b:2dd3%9]:1900 *:* 3084 UDP [fe80::d6f:942b:240b:2dd3%9]:57980 *:* 3084
不过也没看到4242端口
不过查到了:
C:\Windows\system32>netstat -ano | findstr /i 4242 TCP 127.0.0.1:4242 0.0.0.0:0 LISTENING 20584
然后再去研究具体常见参数和具体含义
cmd:
netstat -na | find "8080"
bash:
netstat -na | grep "8080"
PowerShell:
netstat -na | Select-String "8080"
和:
netstat -np <protocol> | find "port #"
举例:
netstat -np TCP | find "80"
netstat –aon | find "<port number>"
搭配:
taskkill /F /pid <process ID>
windows netstat
【总结】
windows中命令:netstat
语法;
netstat [-a] [-e] [-n] [-o] [-p <Protocol>] [-r] [-s] [<Interval>]
参数含义:
- -a:显示所有
- Displays all active TCP connections and the TCP and UDP ports on which the computer is listening.
- -e:
- Displays Ethernet statistics, such as the number of bytes and packets sent and received. This parameter can be combined with -s.
- -n:numerical,以数字形式显示(地址和端口号)
- Displays active TCP connections, however, addresses and port numbers are expressed numerically and no attempt is made to determine names.
- -o:显示Owning (Process ID)=所属的进程ID=PID
- Displays active TCP connections and includes the process ID (PID) for each connection. You can find the application based on the PID on the Processes tab in Windows Task Manager. This parameter can be combined with -a, -n, and -p.
- -p Shows connections for the protocol specified by Protocol. In this case, the Protocol can be tcp, udp, tcpv6, or udpv6. If this parameter is used with -s to display statistics by protocol, Protocol can be tcp, udp, icmp, ip, tcpv6, udpv6, icmpv6, or ipv6.
- -s Displays statistics by protocol. By default, statistics are shown for the TCP, UDP, ICMP, and IP protocols. If the IPv6 protocol is installed, statistics are shown for the TCP over IPv6, UDP over IPv6, ICMPv6, and IPv6 protocols. The -p parameter can be used to specify a set of protocols.
- -r Displays the contents of the IP routing table. This is equivalent to the route print command.
- Redisplays the selected information every Interval seconds. Press CTRL+C to stop the redisplay. If this parameter is omitted, netstat prints the selected information only once.
- /? Displays help at the command prompt.
注:
多个参数,可以分开,也可以写在一起:
比如:
netstat -ano netstat -a -n -o
是等价的。
常见组合:
(1)显示所有连接的端口号和 对应pid=进程号
netstat -ano
(2)显示tcp协议的链接
netstat -np TCP
转载请注明:在路上 » 【已解决】windows中netstat命令的语法和常见用法和含义