TCP端口的连通性
方法一:TCP协议是面向连接的,可以直接通过telnet命令连接
telent ip port
➜ packages telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
方法二:使用nc(netcat)命令
nc -vz ip port
➜ packages nc -vz 127.0.0.1 80
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif lo0
src 127.0.0.1 port 49594
dst 127.0.0.1 port 80
rank info not available
TCP aux info available
Connection to 127.0.0.1 port 80 [tcp/http] succeeded!
➜ packages nc -zv 127.0.0.1 8080
nc: connectx to 127.0.0.1 port 8080 (tcp) failed: Connection refused
nc相关option:
-u UDP mode
-v Verbose
-z Zero-I/O mode [used for scanning]
UDP端口的连通性
UDP协议是无连接的,不需要握手建立连接,数据发送后,server端也不会返回确认信息。
方法一:使用nc(netcat)命令
nc -uvz ip port
➜ packages nc -uvz 127.0.0.1 80
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif (null)
src 127.0.0.1 port 54152
dst 127.0.0.1 port 80
rank info not available
Connection to 127.0.0.1 port 80 [udp/http] succeeded!
总结:nc(netcat)是专门用于TCP/UDP连接和监听的命令,建议大家直接使用nc。