Total Pageviews

Wednesday, 17 July 2024

Mac OS 系统下,查看网络端口号的方式

主要有 netstat、lsof、网络实用工具(Mac OS 自带的工具)

 

1. netstat

1
2
3
4
5
6
7
8
9
$ netstat --help
Usage:  netstat [-AaLlnW] [-f address_family | -p protocol]
        netstat [-gilns] [-f address_family]
        netstat -i | -I interface [-w wait] [-abdgRtS]
        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]

 

1)netstat 默认查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ netstat
Active Internet connections
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)   
tcp4       0      0  192.168.31.191.62976   ti-in-f113.1e100.https SYN_SENT  
tcp4       0    371  192.168.31.191.62975   a104-118-66-248..https ESTABLISHED
tcp4       0      0  localhost.62905        localhost.cslistener   ESTABLISHED
tcp4       0      0  localhost.8084         localhost.62904        ESTABLISHED
tcp4       0      0  localhost.62904        localhost.8084         ESTABLISHED
tcp4       0      0  192.168.31.191.50367   101.226.211.105.http-a ESTABLISHED
tcp4       0      0  192.168.31.191.59890   47.95.6.112.ssh        ESTABLISHED
tcp4       0      0  192.168.31.191.56988   tk-in-f188.1e100.5228  ESTABLISHED
tcp4       0      0  192.168.31.191.56286   17.252.156.21.5223     ESTABLISHED
tcp4       0      0  localhost.60280        localhost.60281        ESTABLISHED
tcp4      37      0  192.168.31.191.62061   mail.eclipse.org.https CLOSE_WAIT
tcp4       0      0  localhost.30100        localhost.54910        CLOSE_WAIT
tcp4       0      0  localhost.ssh          localhost.56570        ESTABLISHED

 

2)netstat 查看端口号

netstat -an | grep 9000

 

3)netstat 查看监听

netstat -an -p tcp | grep -iE "LISTEN"

 

 

2. lsof

1)查看端口号

sudo lsof -i :9000

1
2
3
4
5
6
7
$ sudo lsof -i :9000
COMMAND   PID   USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
php-fpm 34223   root   11u  IPv4 0x452eab886c917f5      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 34224 nobody    0u  IPv4 0x452eab886c917f5      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 34224 nobody    7u  IPv4 0x452eab89a96e275      0t0  TCP localhost:cslistener->localhost:63956 (CLOSE_WAIT)
php-fpm 34225 nobody    0u  IPv4 0x452eab886c917f5      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 34226 nobody    0u  IPv4 0x452eab886c917f5      0t0  TCP localhost:cslistener (LISTEN)

 

2)lsof 更多命令

sudo lsof -i :9000
sudo lsof -P -i tcp:80
sudo lsof -i -P | grep -i "listen"

 

 

3. 网络实用工具Network Utility

Mac OS 10.9 以后,自带的网络工具就隐藏了,找到打开步骤如下

方法1)spotlight 搜索

查看Mac系统右上角,点击放大镜搜索 ——> 输入 Network Utility. 双击显示的Network Utility图标。


No comments:

Post a Comment