Linux, 檢查端口開放的七種方法c#
telnetssh
# yum -y install telnet # telnet 10.0.0.51 22 Trying 10.0.0.51... Connected to 10.0.0.51. Escape character is '^]'. SSH-2.0-OpenSSH_7.4 按ctrl+alt+]退出
2. nmaptcp
# nmap -p 22 10.0.0.51 Starting Nmap 6.40 ( http://nmap.org ) at 2018-08-27 09:32 CST Nmap scan report for bogon (10.0.0.51) Host is up (0.000043s latency). PORT STATE SERVICE 22/tcp open ssh --> open即開放 Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds
3. ncide
# nc -z -v -n 10.0.0.51 22 Ncat: Version 7.50 ( https://nmap.org/ncat ) Ncat: Connected to 10.0.0.51:22. Ncat: 0 bytes sent, 0 bytes received in 0.03 seconds.
參數說明:ci
-z: 端口掃描模式
it
-v: 顯示詳細信息
io
-n: 以數字的形式顯示,即不反向解析
class
4. tcpingmap
# yum -y install tcping # tcping 10.0.0.51 22 10.0.0.51 port 22 open.
5. grep
echo >/dev/tcp/localhost/22 && echo "open"
6. netstat|ss
# ss -ltnp|grep -w 22 LISTEN 0 128 *:22 *:* users:(("sshd",pid=1210,fd=3)) LISTEN 0 128 :::22 :::* users:(("sshd",pid=1210,fd=4))
7. lsof
# lsof -i :22 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 1210 root 3u IPv4 20218 0t0 TCP *:ssh (LISTEN) sshd 1210 root 4u IPv6 20220 0t0 TCP *:ssh (LISTEN) sshd 23635 root 3u IPv4 188315 0t0 TCP bogon:ssh->bogon:acmsoda (ESTABLISHED) sshd 23789 root 3u IPv4 192038 0t0 TCP bogon:ssh->bogon:7238 (ESTABLISHED)