Find process running on port: Difference between revisions
Jump to navigation
Jump to search
m
→Find process running on port in Mac
mNo edit summary |
|||
| (18 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== | == Find process running on port in Windows == | ||
* {{ | * GUI software: [https://www.nirsoft.net/utils/cports.html CurrPorts: Monitoring TCP/IP network connections on Windows] | ||
* {{Mac}} {{kbd | key=<nowiki>netstat -vanp tcp | grep 4444</nowiki>}} or {{kbd | key=<nowiki>lsof -i tcp:4444</nowiki>}} | * GUI software: [https://docs.microsoft.com/zh-tw/sysinternals/downloads/tcpview Windows 的 TCPView - Windows Sysinternals | Microsoft Docs] | ||
* {{Linux}} CentOS7 {{kbd | key=<nowiki>netstat - | * Command: {{kbd | key=<nowiki>netstat –na | find "<PORT>"</nowiki>}} e.g. {{kbd | key=<nowiki>netstat –na | find "4444"</nowiki>}} or {{kbd | key = <nowiki>netstat -a | find "3306"</nowiki>}} (note: require the '''double quote''' symbol, not single quote symbol) for {{Win}}<ref>[http://technet.microsoft.com/en-us/library/bb490947.aspx Netstat]</ref> | ||
* Command to kill: [https://www.npmjs.com/package/kill-port kill-port - npm] | |||
== Find process running on port in Mac/Linux == | |||
* {{Mac}} | |||
** {{kbd | key=<nowiki>netstat -vanp tcp | grep 4444</nowiki>}} or | |||
** {{kbd | key=<nowiki>lsof -i tcp:4444</nowiki>}} or {{kbd | key=<nowiki>lsof -i :4444</nowiki>}}<ref>[https://man7.org/linux/man-pages/man8/lsof.8.html lsof(8) - Linux manual page]</ref> | |||
** {{kbd | key=<nowiki>sudo lsof -i -P | grep LISTEN | grep :$PORT</nowiki>}}<ref>[https://stackoverflow.com/questions/4421633/who-is-listening-on-a-given-tcp-port-on-mac-os-x macos - Who is listening on a given TCP port on Mac OS X? - Stack Overflow]</ref> | |||
* {{Linux}} | |||
** [http://linux.die.net/man/1/nmap nmap] "Network exploration tool and security / port scanner." e.g. {{kbd | key = <nowiki>nmap -p 80,443 ip</nowiki>}} | |||
** [http://linux.die.net/man/8/ss ss] "utility to investigate sockets" e.g. {{kbd | key = <nowiki>ss -tnlp | grep 80</nowiki>}} or using OR operator<ref>[http://www.thegeekstuff.com/2011/10/grep-or-and-not-operators/ 7 Linux Grep OR, Grep AND, Grep NOT Operator Examples]</ref> {{kbd | key = <nowiki>ss -tnlp | grep '80\|443'</nowiki>}} | |||
** [http://linuxcommand.org/man_pages/ps1.html ps] List the current processes. Input {{kbd | key = <nowiki>ps -aux | grep "PORT_NUMBER"</nowiki>}} e.g. {{kbd | key = <nowiki>ps -aux | grep 443</nowiki>}} | |||
** [https://docs.oracle.com/cd/E19504-01/802-5753/6i9g71m3i/index.html netstat Command] {{kbd | key=<nowiki>netstat -tulpn | grep LISTEN</nowiki>}} e.g. | |||
** [https://docs.docker.com/engine/reference/commandline/port/ docker port | Docker Documentation] | |||
== Find process running on port in Windows == | |||
* {{Linux}} CentOS7: | |||
** {{kbd | key=<nowiki>netstat -na | grep ":<port>"</nowiki>}} e.g. {{kbd | key=<nowiki>sudo netstat -pan | grep ":80"</nowiki>}} or | |||
** {{kbd | key=<nowiki>ps -elf | grep <port></nowiki>}} | |||
<pre> | <pre> | ||
| Line 20: | Line 39: | ||
java 15476 user 8u IPv6 0x8eb77926a50f8a53 0t0 TCP *:krb524 (LISTEN) | java 15476 user 8u IPv6 0x8eb77926a50f8a53 0t0 TCP *:krb524 (LISTEN) | ||
## Liunx | |||
## After running process on mac, and then input the command: sudo netstat -pan | grep ":80" | |||
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 23370/python3 | |||
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 23025/nginx: master | |||
tcp6 0 0 :::80 :::* LISTEN 23025/nginx: master | |||
tcp6 0 0 :::8000 :::* LISTEN 22001/docker-proxy | |||
</pre> | </pre> | ||
| Line 27: | Line 52: | ||
解決方式: 請將 <port> 加上雙引號,例如: {{kbd | key=<nowiki>netstat –na | find "4444"</nowiki>}} | 解決方式: 請將 <port> 加上雙引號,例如: {{kbd | key=<nowiki>netstat –na | find "4444"</nowiki>}} | ||
== 相關資料 == | |||
* [http://puremonkey2010.blogspot.com/2010/11/windows-windows-netstat.html 程式扎記: (Windows 技巧) windows常用網路管理指令 - netstat] | |||
* [https://stackoverflow.com/questions/3855127/find-and-kill-process-locking-port-3000-on-mac macos - Find (and kill) process locking port 3000 on Mac - Stack Overflow] | |||
* [https://stackoverflow.com/questions/34815425/how-to-find-all-the-listening-port-in-php sockets - How to find all the listening port in PHP? - Stack Overflow] | |||
* [http://www.techrepublic.com/blog/security/list-open-ports-and-listening-services/443 List open ports and listening services] | |||
* [http://www.cyberciti.biz/faq/find-out-which-service-listening-specific-port/ Linux / UNIX Find Out What Program / Service is Listening on a Specific TCP Port] | |||
* [https://errerrors.blogspot.com/2022/03/fix-control-center-occupy-port-5000-on%20mac.html 解決 Python Flask 網站伺服器無法啟動的問題 [Mac M1]] | |||
== 參考資料 == | == 參考資料 == | ||
<references /> | |||
[[Category:Linux]] [[Category:Mac]] [[Category:Windows]] [[Category:Tool]] | [[Category:Linux]] [[Category:Mac]] [[Category:Windows]] [[Category:Tool]] | ||