To see if the port is openUse
netstat
Command
a. `netstat -nat | grep <端口号>` , 如命令 `netstat -nat | grep 3306`b. `netstat -nat |grep LISTEN`
Use
lsof
Command
# yongfu-pro at yongfu-pro.local in ~ [22:39:32]$ lsof -n -P -i TCP -s TCP:LISTENCOMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEphp-fpm 387 yongfu-pro 6u IPv4 0x6d7f5d3c3a615679 0t0 TCP 127.0.0.1:9000 (LISTEN)Dropbox 413 yongfu-pro 26u IPv4 0x6d7f5d3c445e2c09 0t0 TCP *:17500 (LISTEN)php-fpm 418 yongfu-pro 0u IPv4 0x6d7f5d3c3a615679 0t0 TCP 127.0.0.1:9000 (LISTEN)php-fpm 419 yongfu-pro 0u IPv4 0x6d7f5d3c3a615679 0t0 TCP 127.0.0.1:9000 (LISTEN)php-fpm 420 yongfu-pro 0u IPv4 0x6d7f5d3c3a615679 0t0 TCP 127.0.0.1:9000 (LISTEN)stunnel 586 yongfu-pro 9u IPv4 0x6d7f5d3c439ff679 0t0 TCP 127.0.0.1:1997 (LISTEN)lsof命令可以列出当前的所有网络情况, 此命令的解释如下:-n 表示主机以ip地址显示-P 表示端口以数字形式显示,默认为端口名称-i 意义较多,具体 man lsof, 主要是用来过滤lsof的输出结果-s 和 -i 配合使用,用于过滤输出
Use
telnet
Command
检查本机的3306端口是否打开, 如下telnet 127.0.0.1 3306 若该端口没有打开,则会自动退出,并显示如下内容:Trying 127.0.0.1...telnet: connect to address 127.0.0.1: Connection refusedtelnet: Unable to connect to remote host
If the port is open, it will remain connected.
Exit Method: Ctrl +] then CTRL + C
Or: Ctrl + D and enter key
Use
nc
Command
# yongfu at yf-mac.local in ~ [9:33:14]$ nc -w 10 -n -z 127.0.0.1 1990-1999Connection to 127.0.0.1 port 1997 [tcp/*] succeeded!Connection to 127.0.0.1 port 1998 [tcp/*] succeeded!-w 10 表示等待连接时间为10秒-n 尽量将端口号名称转换为端口号数字-z 对需要检查的端口没有输入输出,用于端口扫描模式127.0.0.1 需要检查的ip地址1990-1999 可以是一个端口,也可以是一段端口 返回结果为开放的端口, 如本例中的 1997 和 1998 端口
Use
网络实用工具
Network Utility is Apple's own network analysis tool
Before 10.8, located in launchpad --> 其他--> 网络实用工具
The app is hidden after 10.9, but can be spotlight
searched 网络实用工具
or 最左上角的苹果标志 --> 关于本机 -->点按‘系统报告‘ --> 标题栏的‘窗口‘ --> 网络实用工具 --> 点按‘端口扫描‘
Spotlight Search
Or
In the network using the tool interface, select the ' Port Scan ' tab, enter an IP address to scan the open interface.
Here we enter 127.0.0.1 to view the port opening of this machine.
In the case of command line, this method is highly deprecated because the graphical tool is scanned sequentially from 0 to 65535 in the order of the ports, too slow. Recommended command line mode.
Mac OS X view network port conditions