[iyunv@B ~]# nmap 10.0.1.161 -p1-65535
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:11 CST
Nmap scan report for 10.0.1.161
Host is up (0.00017s latency).
Not shown: 65531 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
873/tcp open rsync
13306/tcp open unknown
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 2.49 seconds
[iyunv@B ~]#
如果不加-p1-65535,对于未知服务的端口(A机器的13306端口)就没法扫描到
[iyunv@B ~]# nmap 10.0.1.161
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:12 CST
Nmap scan report for 10.0.1.161
Host is up (0.000089s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
873/tcp open rsync
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.43 seconds
[iyunv@B ~]#
[iyunv@B ~]# nmap 10.0.1.161 -p20-200,7777,8888
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:32 CST
Nmap scan report for 10.0.1.161
Host is up (0.00038s latency).
Not shown: 179 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
7777/tcp open cbt
8888/tcp open sun-answerbook
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.17 seconds
[iyunv@B ~]#
扫描udp端口
先查看哪些ipv4的监听,使用grep -v排除回环接口上的监听
netstat -lnup --inet |grep -v 127.0.0.1
[iyunv@A ~]# netstat -lnup --inet |grep -v 127.0.0.1
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:111 0.0.0.0:* 21505/rpcbind
udp 0 0 0.0.0.0:631 0.0.0.0:* 1930/cupsd
udp 0 0 10.0.1.161:123 0.0.0.0:* 2261/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 2261/ntpd
udp 0 0 0.0.0.0:904 0.0.0.0:* 21505/rpcbind
[iyunv@A ~]#
-sU:表示udp scan , udp端口扫描
-Pn:不对目标进行ping探测(不判断主机是否在线)(直接扫描端口)
对于udp端口扫描比较慢,扫描完6万多个端口需要20分钟左右
[iyunv@B ~]# nmap -sU 10.0.1.161 -Pn
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:16 CST
Stats: 0:12:54 elapsed; 0 hosts completed (1 up), 1 undergoing UDP Scan
UDP Scan Timing: About 75.19% done; ETC: 10:33 (0:04:16 remaining)
Stats: 0:12:55 elapsed; 0 hosts completed (1 up), 1 undergoing UDP Scan
UDP Scan Timing: About 75.29% done; ETC: 10:33 (0:04:15 remaining)
Nmap scan report for 10.0.1.161
Host is up (0.0011s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
111/udp open rpcbind
123/udp open ntp
631/udp open|filtered ipp
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 1081.27 seconds
[iyunv@B ~]#
扫描多个IP用法
中间用空格分开
[iyunv@B ~]# nmap 10.0.1.161 10.0.1.162
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:18 CST
Nmap scan report for 10.0.1.161
Host is up (0.000060s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
873/tcp open rsync
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap scan report for 10.0.1.162
Host is up (0.0000070s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
Nmap done: 2 IP addresses (2 hosts up) scanned in 0.26 seconds
[iyunv@B ~]#
也可以采用下面方式逗号隔开
nmap 10.0.1.161,162
[iyunv@B ~]# nmap 10.0.1.161,162
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:19 CST
Nmap scan report for 10.0.1.161
Host is up (0.00025s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
873/tcp open rsync
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap scan report for 10.0.1.162
Host is up (0.0000080s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
Nmap done: 2 IP addresses (2 hosts up) scanned in 0.81 seconds
[iyunv@B ~]#
扫描连续的ip地址
[iyunv@B ~]# nmap 10.0.1.161-162
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:20 CST
Nmap scan report for 10.0.1.161
Host is up (0.00011s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
873/tcp open rsync
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap scan report for 10.0.1.162
Host is up (0.0000030s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
Nmap done: 2 IP addresses (2 hosts up) scanned in 0.25 seconds
[iyunv@B ~]#
扫描一个子网网段所有IP
[iyunv@B ~]# nmap 10.0.3.0/24
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:21 CST
Nmap scan report for 10.0.3.1
Host is up (0.020s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
23/tcp open telnet
6666/tcp open irc
8888/tcp open sun-answerbook
Nmap scan report for 10.0.3.2
Host is up (0.012s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
21/tcp filtered ftp
22/tcp filtered ssh
23/tcp open telnet
Nmap scan report for 10.0.3.3
Host is up (0.018s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
21/tcp filtered ftp
22/tcp filtered ssh
23/tcp open telnet
Nmap done: 256 IP addresses (3 hosts up) scanned in 14.91 seconds
[iyunv@B ~]#
[iyunv@B ~]# cat ip.txt
10.0.1.161
10.0.1.162
[iyunv@B ~]# nmap -iL ip.txt
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:23 CST
Nmap scan report for 10.0.1.161
Host is up (0.00030s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
873/tcp open rsync
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap scan report for 10.0.1.162
Host is up (0.0000070s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
Nmap done: 2 IP addresses (2 hosts up) scanned in 0.68 seconds
[iyunv@B ~]#
扫描地址段是排除某个IP地址
nmap 10.0.1.161-162 --exclude 10.0.1.162
用法如下
[iyunv@B ~]# nmap 10.0.1.161-162 --exclude 10.0.1.162
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:24 CST
Nmap scan report for 10.0.1.161
Host is up (0.0022s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
873/tcp open rsync
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.53 seconds
[iyunv@B ~]#
扫描时排除多个IP地址
排除连续的,可以使用横线连接起来
nmap 10.0.1.161-163 --exclude 10.0.1.162-163
[iyunv@B ~]# nmap 10.0.1.161-163 --exclude 10.0.1.162-163
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:25 CST
Nmap scan report for 10.0.1.161
Host is up (0.00023s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
873/tcp open rsync
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.56 seconds
[iyunv@B ~]#
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:27 CST
Nmap scan report for 10.0.1.162
Host is up (0.0000030s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
Nmap done: 1 IP address (1 host up) scanned in 0.12 seconds
[iyunv@B ~]#
[iyunv@B ~]# cat ex.txt
10.0.1.161
10.0.1.163
[iyunv@B ~]# nmap 10.0.1.161-163 --excludefile ex.txt
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 10:29 CST
Nmap scan report for 10.0.1.162
Host is up (0.0000050s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
Nmap done: 1 IP address (1 host up) scanned in 0.18 seconds
[iyunv@B ~]#