测试端口的几种方式
1.telnet
telnet ip port
success
root@hecs-170280:~# telnet 127.0.0.1 80
Trying 127.0.0.1…
Connected to 127.0.0.1.
Escape character is ‘^]’.
fail
root@hecs-170280:~# telnet 127.0.0.1 8080
Trying 127.0.0.1…
telnet: Unable to connect to remote host: Connection refused
2.nc
nc -zv ip port
success
root@hecs-170280:~# nc -zv 127.0.0.1 80
Connection to 127.0.0.1 80 port [tcp/http] succeeded!
fail
root@hecs-170280:~# nc -zv 127.0.0.1 8080
nc: connect to 127.0.0.1 port 8080 (tcp) failed: Connection refused
3.ssh
ssh -v ip -p port
success
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 80.
debug1: Connection established
fail
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 8080.
debug1: connect to address 127.0.0.1 port 8080: Connection refused
4.curl
curl -v ip:port
success
root@hecs-170280:~# curl -v 127.0.0.1:80
- Trying 127.0.0.1:80…
- Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
fail
root@hecs-170280:~# curl -v 127.0.0.1:8080
- Trying 127.0.0.1:8080…
- connect to 127.0.0.1 port 8080 failed: Connection refused
5.wget
wget ip:port
success
root@hecs-170280:~# wget 127.0.0.1:80
–2023-08-06 19:21:45-- http://127.0.0.1/
Connecting to 127.0.0.1:80… connected.
fail
root@hecs-170280:~# wget 127.0.0.1:8080
–2023-08-06 19:21:43-- http://127.0.0.1:8080/
Connecting to 127.0.0.1:8080… failed: Connection refused.
6.lsof
只适合查看本地端口
lsof -i:port
7.netstat
netstat -lntp
# -l 列出所有端口
# -n 以数字显示地址和端口
# -t 列出tcp协议连接,-u列出udp连接,-a列出所有
# -p 显示占用该端口的进程