Mac 中 查看网络连接数
-n 表示不显示主机名 -P 表示不显示端口俗称 不加 sudo 只能查看以当前用户运行的程序
当前用户名下启动的链接数
$ lsof -itcp -n
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
CalendarA 400 <user> 47u IPv4 0x25bdd13901adaa17 0t0 TCP 127.0.0.1:53564->127.0.0.1:12639 (ESTABLISHED)
redis-ser 505 <user> 6u IPv4 0x25bdd138dd307397 0t0 TCP 127.0.0.1:6379 (LISTEN)
redis-ser 505 <user> 7u IPv6 0x25bdd138da0b4a57 0t0 TCP [::1]:6379 (LISTEN)
1
2
3
4
5
2
3
4
5
当前用户名下监听的端口
$ lsof -itcp -stcp:listen
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
redis-ser 505 <user> 6u IPv4 0x25bdd138dd307397 0t0 TCP localhost:6379 (LISTEN)
redis-ser 505 <user> 7u IPv6 0x25bdd138da0b4a57 0t0 TCP localhost:6379 (LISTEN)
1
2
3
4
2
3
4
附录:使用 netstat 命令查看连接数
$ netstat -antvp tcp
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state) rhiwat shiwat pid epid state options
tcp4 0 0 127.0.0.1.42103 127.0.0.1.64608 ESTABLISHED 431859 146988 159 0 0x0182 0x00000004
tcp4 0 0 127.0.0.1.64608 127.0.0.1.42103 ESTABLISHED 374836 146988 1038 0 0x0182 0x00020000
tcp4 0 0 *.88 *.* LISTEN 131072 131072 174 0 0x0180 0x00000006
tcp6 0 0 *.88 *.* LISTEN 131072 131072 174 0 0x0180 0x00000006
tcp4 0 0 *.548 *.* LISTEN 131072 131072 1 0 0x0180 0x00000006
tcp6 0 0 *.548 *.* LISTEN 131072 131072 1 0 0x0180 0x00000006
tcp4 0 0 *.445 *.* LISTEN 131072 131072 1 0 0x0180 0x00000006
tcp6 0 0 *.445 *.* LISTEN 131072 131072 1 0 0x0180 0x00000006
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11