c安康nc# 查找端口占用
lsof
用默认用户(非root)登录终端,查看 88 端口占用情况,查不到,然后加 sudo 之后,就可以查到,因为 88 端口是被 root 占用的,所以普通用户查不到。
用法:
- lsof -i:端口
- lsof -i tcp:端口
(base) ➜ OGMS lsof -i:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
SmartGate 39277 shenchaoran 187u IPv4 0xb33e9d506a5ff057 0t0 TCP 10.64.114.42:56292->10.64.114.42:hbci (ESTABLISHED)
Google 39380 shenchaoran 57u IPv4 0xb33e9d503503b6d7 0t0 TCP localhost:56258->localhost:hbci (CLOSE_WAIT)
Google 39380 shenchaoran 77u IPv4 0xb33e9d505e83a3d7 0t0 TCP localhost:56266->localhost:hbci (CLOSE_WAIT)
Google 39380 shenchaoran 90u IPv4 0xb33e9d503bb393d7 0t0 TCP localhost:56268->localhost:hbci (CLOSE_WAIT)
Google 39380 shenchaoran 101u IPv4 0xb33e9d506d06cd57 0t0 TCP localhost:56290->localhost:hbci (ESTABLISHED)
Google 39380 shenchaoran 102u IPv4 0xb33e9d50607ce057 0t0 TCP localhost:56270->localhost:hbci (CLOSE_WAIT)
Google 39380 shenchaoran 110u IPv4 0xb33e9d503bcc1a57 0t0 TCP localhost:56272->localhost:hbci (CLOSE_WAIT)
Google 39380 shenchaoran 112u IPv4 0xb33e9d50607cc3d7 0t0 TCP localhost:56274->localhost:hbci (CLOSE_WAIT)
(base) ➜ OGMS sudo lsof -i:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
SmartGate 39277 shenchaoran 187u IPv4 0xb33e9d506a5ff057 0t0 TCP 10.64.114.42:56292->10.64.114.42:hbci (ESTABLISHED)
Google 39380 shenchaoran 57u IPv4 0xb33e9d503503b6d7 0t0 TCP localhost:56258->localhost:hbci (CLOSE_WAIT)
Google 39380 shenchaoran 77u IPv4 0xb33e9d505e83a3d7 0t0 TCP localhost:56266->localhost:hbci (CLOSE_WAIT)
Google 39380 shenchaoran 90u IPv4 0xb33e9d503bb393d7 0t0 TCP localhost:56268->localhost:hbci (CLOSE_WAIT)
Google 39380 shenchaoran 101u IPv4 0xb33e9d506d06cd57 0t0 TCP localhost:56290->localhost:hbci (ESTABLISHED)
Google 39380 shenchaoran 102u IPv4 0xb33e9d50607ce057 0t0 TCP localhost:56270->localhost:hbci (CLOSE_WAIT)
Google 39380 shenchaoran 110u IPv4 0xb33e9d503bcc1a57 0t0 TCP localhost:56272->localhost:hbci (CLOSE_WAIT)
Google 39380 shenchaoran 112u IPv4 0xb33e9d50607cc3d7 0t0 TCP localhost:56274->localhost:hbci (CLOSE_WAIT)
node 60925 root 26u IPv4 0xb33e9d50601b1d57 0t0 TCP *:hbci (LISTEN)
node 60925 root 47u IPv4 0xb33e9d50601b13d7 0t0 TCP localhost:hbci->localhost:56290 (ESTABLISHED)
node 60925 root 49u IPv4 0xb33e9d50524f4057 0t0 TCP 10.64.114.42:hbci->10.64.114.42:56292 (ESTABLISHED)
netstat
在 linux 上面使用的方法通常为:netstat -nltp
-a (all)显示所有选项,默认不显示LISTEN相关 -t (tcp)仅显示tcp相关选项 -u (udp)仅显示udp相关选项 -n 拒绝显示别名,能显示数字的全部转化成数字。 -l 仅列出有在 Listen (监听) 的服務状态
-p 显示建立相关链接的程序名 -r 显示路由信息,路由表 -e 显示扩展信息,例如uid等 -s 按各个协议进行统计 -c 每隔一个固定时间,执行该netstat命令
在Mac上正确使用的方法是:即-f需要加上地址族,-p需要加上协议TCP或者UDP等
netstat [-AaLlnW] [-f address_family | -p protocol]
netstat [-gilns] [-v] [-f address_family] [-I interface]
netstat -i | -I interface [-w wait] [-c queue] [-abdgqRtS]
netstat -s [-s] [-f address_family | -p protocol] [-w wait]
netstat -i | -I interface -s [-f address_family | -p protocol]
netstat -m [-m]
netstat -r [-Aaln] [-f address_family]
netstat -rs [-s]
- 如果需要查询inet:netstat -anvf inet
- 如果需要查询TCP:netstat -anvp tcp
- 如果需要查询UDP:netstat -anvp udp
(base) ➜ OGMS netstat -anvp tcp | grep 3000
tcp4 0 0 10.64.114.42.3000 10.64.114.42.56292 ESTABLISHED 407647 146988 60925 0 0x0182 0x0000010c
tcp4 0 0 10.64.114.42.56292 10.64.114.42.3000 ESTABLISHED 407938 146988 39277 0 0x0102 0x00000100
tcp4 0 0 127.0.0.1.3000 127.0.0.1.56290 ESTABLISHED 407546 146988 60925 0 0x0182 0x0000010c
tcp4 0 0 127.0.0.1.56290 127.0.0.1.3000 ESTABLISHED 407938 146988 39380 0 0x0102 0x00000008
tcp4 0 0 127.0.0.1.3000 127.0.0.1.56274 FIN_WAIT_2 407347 146988 60925 0 0x21b1 0x00000104
tcp4 0 0 127.0.0.1.56274 127.0.0.1.3000 CLOSE_WAIT 391642 146988 39380 0 0x0122 0x00000008
tcp4 0 0 127.0.0.1.3000 127.0.0.1.56272 FIN_WAIT_2 407824 146988 60925 0 0x21b1 0x00000104
tcp4 0 0 127.0.0.1.56272 127.0.0.1.3000 CLOSE_WAIT 405588 146988 39380 0 0x0122 0x00000008
tcp4 0 0 127.0.0.1.3000 127.0.0.1.56270 FIN_WAIT_2 407347 146988 60925 0 0x21b1 0x00000104
tcp4 0 0 127.0.0.1.56270 127.0.0.1.3000 CLOSE_WAIT 391355 146988 39380 0 0x0122 0x00000008
tcp4 0 0 127.0.0.1.3000 127.0.0.1.56268 FIN_WAIT_2 406871 146988 60925 0 0x21b1 0x00000104
tcp4 0 0 127.0.0.1.56268 127.0.0.1.3000 CLOSE_WAIT 363495 146988 39380 0 0x0122 0x00000008
tcp4 0 0 127.0.0.1.3000 127.0.0.1.56266 FIN_WAIT_2 406834 146988 60925 0 0x21b1 0x00000104
tcp4 0 0 127.0.0.1.56266 127.0.0.1.3000 CLOSE_WAIT 332394 146988 39380 0 0x0122 0x00000008
tcp4 0 0 127.0.0.1.3000 127.0.0.1.56258 FIN_WAIT_2 406349 146988 60925 0 0x21b1 0x00000104
tcp4 0 0 127.0.0.1.56258 127.0.0.1.3000 CLOSE_WAIT 338058 146988 39380 0 0x0122 0x00000008
tcp4 0 0 *.3000 *.* LISTEN 131072 131072 60925 0 0x0180 0x00000106
ssh
sudo launchctl stop com.openssh.sshd
sudo launchctl start com.openssh.sshd
wifi 卡死
活动监视器里杀掉 airportd
sudo kill -9 `ps aux | grep -v grep | grep /usr/libexec/airportd | awk '{print $2}'`