使用-sP参数对对应主机段的主机发送ICMP报文,可以查询到哪些主机是存活的。
[root@localhost ~]# nmap -sP 192.168.8.0/24
Starting Nmap 6.40 ( http://nmap.org ) at 2018-07-10 14:32 CST
Nmap scan report for 192.168.8.0
Host is up (0.0044s latency).
Nmap scan report for 192.168.8.1
Host is up (0.0030s latency).
Nmap scan report for 192.168.8.2
Host is up (0.0022s latency).
Nmap scan report for 192.168.8.3
Host is up (0.0040s latency).
Nmap scan report for 192.168.8.4
Host is up (0.014s latency).
Nmap scan report for 192.168.8.5
Host is up (0.014s latency).
Nmap scan report for 192.168.8.6
Host is up (0.0045s latency).
Nmap scan report for 192.168.8.7
Host is up (0.015s latency).
Nmap scan report for 192.168.8.8
Host is up (0.014s latency).
Nmap scan report for 192.168.8.9
Host is up (0.014s latency).
Nmap scan report for 192.168.8.10
Host is up (0.014s latency).
Nmap scan report for 192.168.8.11
Host is up (0.064s latency).
Nmap scan report for 192.168.8.12
Host is up (0.0069s latency).
Nmap scan report for 192.168.8.13
Host is up (0.014s latency).
Nmap scan report for 192.168.8.14
Host is up (0.014s latency).
Nmap scan report for 192.168.8.15
Host is up (0.064s latency).
Nmap scan report for 192.168.8.16
Host is up (0.0042s latency).
Nmap scan report for 192.168.8.17
Host is up (0.017s latency).
Nmap scan report for 192.168.8.18
Host is up (0.017s latency).
Nmap scan report for 192.168.8.19
Host is up (0.0043s latency).
Nmap scan report for 192.168.8.20
Host is up (0.064s latency).
Nmap scan report for 192.168.8.21
Host is up (0.017s latency).
Nmap scan report for 192.168.8.22
Host is up (0.017s latency).
Nmap scan report for 192.168.8.23
Host is up (0.090s latency).
Nmap scan report for 192.168.8.24
Host is up (0.090s latency).
Nmap scan report for 192.168.8.25
Host is up (0.0021s latency).
Nmap scan report for 192.168.8.26
Host is up (0.063s latency).
Nmap scan report for 192.168.8.27
Host is up (0.063s latency).
Nmap scan report for 192.168.8.28
Host is up (0.015s latency).
Nmap scan report for 192.168.8.29
Host is up (0.015s latency).
Nmap scan report for 192.168.8.30
Host is up (0.015s latency).
Nmap scan report for 192.168.8.31
Host is up (0.015s latency).
Nmap scan report for 192.168.8.32
Host is up (0.015s latency).
Nmap scan report for 192.168.8.33
Host is up (0.015s latency).
Nmap scan report for 192.168.8.34
Host is up (0.015s latency).
Nmap scan report for 192.168.8.35
Host is up (0.015s latency).
Nmap scan report for 192.168.8.36
Host is up (0.063s latency).
Nmap scan report for 192.168.8.37
Host is up (0.089s latency).
Nmap scan report for 192.168.8.38
Host is up (0.019s latency).
Nmap scan report for 192.168.8.39
Host is up (0.019s latency).
Nmap scan report for 192.168.8.40
Host is up (0.019s latency).
Nmap scan report for 192.168.8.41
Host is up (0.019s latency).
Nmap scan report for 192.168.8.42
Host is up (0.086s latency).
Nmap scan report for 192.168.8.43
Host is up (0.0098s latency).
Nmap scan report for 192.168.8.44
Host is up (0.0022s latency).
Nmap scan report for 192.168.8.45
Host is up (0.0041s latency).
Nmap scan report for 192.168.8.46
Host is up (0.0096s latency).
Nmap scan report for 192.168.8.47
Host is up (0.013s latency).
Nmap scan report for 192.168.8.48
Host is up (0.013s latency).
Nmap scan report for 192.168.8.49
Host is up (0.013s latency).
Nmap scan report for 192.168.8.50
Host is up (0.013s latency).
Nmap scan report for 192.168.8.51
Host is up (0.013s latency).
Nmap scan report for 192.168.8.52
Host is up (0.0036s latency).
Nmap scan report for 192.168.8.53
Host is up (0.013s latency).
Nmap scan report for 192.168.8.54
Host is up (0.013s latency).
Nmap scan report for 192.168.8.55
Host is up (0.089s latency).
Nmap scan report for 192.168.8.56
Host is up (0.089s latency).
Nmap scan report for 192.168.8.57
Host is up (0.035s latency).
Nmap scan report for 192.168.8.58
Host is up (0.0027s latency).
Nmap scan report for 192.168.8.59
Host is up (0.0043s latency).
Nmap scan report for 192.168.8.60
Host is up (0.0024s latency).
Nmap scan report for 192.168.8.61
Host is up (0.0094s latency).
Nmap scan report for 192.168.8.62
Host is up (0.0094s latency).
Nmap scan report for 192.168.8.63
Host is up (0.74s latency).
Nmap scan report for 192.168.8.64
Host is up (0.035s latency).
Nmap scan report for 192.168.8.65
Host is up (0.035s latency).
Nmap scan report for 192.168.8.66
Host is up (0.035s latency).
Nmap scan report for 192.168.8.67
Host is up (0.035s latency).
Nmap scan report for 192.168.8.68
Host is up (0.035s latency).
Nmap scan report for 192.168.8.69
Host is up (0.035s latency).
Nmap scan report for 192.168.8.70
Host is up (0.035s latency).
Nmap scan report for 192.168.8.71
Host is up (0.035s latency).
Nmap scan report for 192.168.8.72
Host is up (0.0032s latency).
Nmap scan report for 192.168.8.73
Host is up (0.089s latency).
Nmap scan report for 192.168.8.74
Host is up (0.035s latency).
Nmap scan report for 192.168.8.75
Host is up (0.035s latency).
Nmap scan report for 192.168.8.76
Host is up (0.035s latency).
Nmap scan report for 192.168.8.77
Host is up (0.0041s latency).
Nmap scan report for 192.168.8.78
Host is up (0.0029s latency).
Nmap scan report for 192.168.8.79
Host is up (0.0039s latency).
Nmap scan report for 192.168.8.80
Host is up (0.0038s latency).
Nmap scan report for 192.168.8.81
Host is up (0.089s latency).
Nmap scan report for 192.168.8.82
Host is up (0.0040s latency).
Nmap scan report for 192.168.8.83
Host is up (0.034s latency).
Nmap scan report for 192.168.8.84
Host is up (0.034s latency).
Nmap scan report for 192.168.8.85
Host is up (0.0034s latency).
Nmap scan report for 192.168.8.86
Host is up (0.0042s latency).
Nmap scan report for 192.168.8.87
Host is up (0.0057s latency).
Nmap scan report for 192.168.8.88
Host is up (0.017s latency).
Nmap scan report for 192.168.8.89
Host is up (0.0092s latency).
Nmap scan report for 192.168.8.90
Host is up (0.0038s latency).
Nmap scan report for 192.168.8.91
Host is up (0.0035s latency).
Nmap scan report for 192.168.8.92
Host is up (0.017s latency).
Nmap scan report for 192.168.8.93
Host is up (0.0072s latency).
Nmap scan report for 192.168.8.94
Host is up (0.0071s latency).
Nmap scan report for 192.168.8.95
Host is up (0.017s latency).
Nmap scan report for 192.168.8.96
Host is up (0.016s latency).
Nmap scan report for 192.168.8.97
Host is up (0.0091s latency).
Nmap scan report for 192.168.8.98
Host is up (0.0037s latency).
Nmap scan report for 192.168.8.99
Host is up (0.14s latency).
Nmap scan report for 192.168.8.100
Host is up (0.016s latency).
Nmap scan report for 192.168.8.101
Host is up (0.0086s latency).
Nmap scan report for 192.168.8.102
Host is up (0.0085s latency).
Nmap scan report for 192.168.8.103
Host is up (0.0042s latency).
Nmap scan report for 192.168.8.104
Host is up (0.0023s latency).
Nmap scan report for 192.168.8.105
Host is up (0.0077s latency).
Nmap scan report for 192.168.8.106
Host is up (0.015s latency).
Nmap scan report for 192.168.8.107
Host is up (0.015s latency).
Nmap scan report for 192.168.8.108
Host is up (0.015s latency).
Nmap scan report for 192.168.8.109
Host is up (0.015s latency).
Nmap scan report for 192.168.8.110
Host is up (0.012s latency).
Nmap scan report for 192.168.8.111
Host is up (0.085s latency).
Nmap scan report for 192.168.8.112
Host is up (0.0036s latency).
Nmap scan report for 192.168.8.113
Host is up (0.015s latency).
Nmap scan report for 192.168.8.114
Host is up (0.012s latency).
Nmap scan report for 192.168.8.115
Host is up (0.012s latency).
Nmap scan report for 192.168.8.116
Host is up (0.014s latency).
Nmap scan report for 192.168.8.117
Host is up (0.10s latency).
Nmap scan report for 192.168.8.118
Host is up (0.0035s latency).
Nmap scan report for 192.168.8.119
Host is up (0.013s latency).
Nmap scan report for 192.168.8.120
Host is up (0.013s latency).
Nmap scan report for 192.168.8.121
Host is up (0.013s latency).
Nmap scan report for 192.168.8.122
Host is up (0.013s latency).
Nmap scan report for 192.168.8.123
Host is up (0.013s latency).
Nmap scan report for 192.168.8.124
Host is up (0.057s latency).
Nmap scan report for 192.168.8.125
Host is up (0.0035s latency).
Nmap scan report for 192.168.8.126
Host is up (0.016s latency).
Nmap scan report for 192.168.8.127
Host is up (0.013s latency).
Nmap scan report for 192.168.8.128
Host is up (0.15s latency).
Nmap scan report for 192.168.8.129
Host is up (0.0070s latency).
Nmap scan report for 192.168.8.130
Host is up (0.0033s latency).
Nmap scan report for 192.168.8.131
Host is up (0.0042s latency).
Nmap scan report for 192.168.8.132
Host is up (0.0065s latency).
Nmap scan report for 192.168.8.133
Host is up (0.0064s latency).
Nmap scan report for 192.168.8.134
Host is up (0.0066s latency).
Nmap scan report for 192.168.8.135
Host is up (0.011s latency).
Nmap scan report for 192.168.8.136
Host is up (0.057s latency).
Nmap scan report for 192.168.8.137
Host is up (0.11s latency).
Nmap scan report for 192.168.8.138
Host is up (0.011s latency).
Nmap scan report for 192.168.8.139
Host is up (0.011s latency).
Nmap scan report for 192.168.8.140
Host is up (0.014s latency).
Nmap scan report for 192.168.8.141
Host is up (0.0092s latency).
Nmap scan report for 192.168.8.142
Host is up (0.00023s latency).
Nmap scan report for 192.168.8.143
Host is up (0.00041s latency).
Nmap scan report for 192.168.8.144
Host is up (0.0083s latency).
Nmap scan report for 192.168.8.145
Host is up (0.0090s latency).
Nmap scan report for 192.168.8.146
Host is up (0.016s latency).
Nmap scan report for 192.168.8.147
Host is up (0.0077s latency).
Nmap scan report for 192.168.8.148
Host is up (0.00017s latency).
Nmap scan report for 192.168.8.149
Host is up (0.00028s latency).
Nmap scan report for 192.168.8.150
Host is up (0.0076s latency).
Nmap scan report for 192.168.8.151
Host is up (0.0075s latency).
Nmap scan report for 192.168.8.152
Host is up (0.0074s latency).
Nmap scan report for 192.168.8.153
Host is up (0.00019s latency).
Nmap scan report for 192.168.8.154
Host is up (0.057s latency).
Nmap scan report for 192.168.8.155
Host is up (0.016s latency).
Nmap scan report for 192.168.8.156
Host is up (0.0091s latency).
Nmap scan report for 192.168.8.157
Host is up (0.0090s latency).
Nmap scan report for 192.168.8.158
Host is up (0.0089s latency).
Nmap scan report for 192.168.8.159
Host is up (0.00017s latency).
Nmap scan report for 192.168.8.160
Host is up (0.00023s latency).
Nmap scan report for 192.168.8.161
Host is up (0.0088s latency).
Nmap scan report for 192.168.8.162
Host is up (0.015s latency).
Nmap scan report for 192.168.8.163
Host is up (0.015s latency).
Nmap scan report for 192.168.8.164
Host is up (0.00014s latency).
Nmap scan report for 192.168.8.165
Host is up (0.057s latency).
Nmap scan report for 192.168.8.166
Host is up (0.013s latency).
Nmap scan report for 192.168.8.167
Host is up (0.29s latency).
Nmap scan report for 192.168.8.168
Host is up (0.013s latency).
Nmap scan report for 192.168.8.169
Host is up (0.013s latency).
Nmap scan report for 192.168.8.170
Host is up (0.00020s latency).
Nmap scan report for 192.168.8.171
Host is up (0.0032s latency).
Nmap scan report for 192.168.8.172
Host is up (0.0039s latency).
Nmap scan report for 192.168.8.173
Host is up (0.012s latency).
Nmap scan report for 192.168.8.174
Host is up (0.0020s latency).
Nmap scan report for 192.168.8.175
Host is up (0.0038s latency).
Nmap scan report for 192.168.8.176
Host is up (0.014s latency).
Nmap scan report for 192.168.8.177
Host is up (0.057s latency).
Nmap scan report for 192.168.8.178
Host is up (0.0030s latency).
Nmap scan report for 192.168.8.179
Host is up (0.0059s latency).
Nmap scan report for 192.168.8.180
Host is up (0.057s latency).
Nmap scan report for 192.168.8.181
Host is up (0.0037s latency).
Nmap scan report for 192.168.8.182
Host is up (0.0039s latency).
Nmap scan report for 192.168.8.183
Host is up (0.0043s latency).
Nmap scan report for 192.168.8.184
Host is up (0.0036s latency).
Nmap scan report for 192.168.8.185
Host is up (0.0058s latency).
Nmap scan report for 192.168.8.186
Host is up (0.057s latency).
Nmap scan report for 192.168.8.187
Host is up (0.0034s latency).
Nmap scan report for 192.168.8.188
Host is up (0.0026s latency).
Nmap scan report for 192.168.8.189
Host is up (0.0050s latency).
Nmap scan report for 192.168.8.190
Host is up (0.0033s latency).
Nmap scan report for 192.168.8.191
Host is up (0.014s latency).
Nmap scan report for 192.168.8.192
Host is up (0.014s latency).
Nmap scan report for 192.168.8.193
Host is up (0.014s latency).
Nmap scan report for 192.168.8.194
Host is up (0.014s latency).
Nmap scan report for 192.168.8.195
Host is up (0.014s latency).
Nmap scan report for 192.168.8.196
Host is up (0.014s latency).
Nmap scan report for 192.168.8.197
Host is up (0.0034s latency).
Nmap scan report for 192.168.8.198
Host is up (0.014s latency).
Nmap scan report for 192.168.8.199
Host is up (0.0032s latency).
Nmap scan report for 192.168.8.200
Host is up (0.0031s latency).
Nmap scan report for 192.168.8.201
Host is up (0.089s latency).
Nmap scan report for 192.168.8.202
Host is up (0.0089s latency).
Nmap scan report for 192.168.8.203
Host is up (0.0087s latency).
Nmap scan report for 192.168.8.204
Host is up (0.0086s latency).
Nmap scan report for 192.168.8.205
Host is up (0.085s latency).
Nmap scan report for 192.168.8.206
Host is up (0.089s latency).
Nmap scan report for 192.168.8.207
Host is up (0.0081s latency).
Nmap scan report for 192.168.8.208
Host is up (0.0029s latency).
Nmap scan report for 192.168.8.209
Host is up (0.0028s latency).
Nmap scan report for 192.168.8.210
Host is up (0.0079s latency).
Nmap scan report for 192.168.8.211
Host is up (0.085s latency).
Nmap scan report for 192.168.8.212
Host is up (0.085s latency).
Nmap scan report for 192.168.8.213
Host is up (0.088s latency).
Nmap scan report for 192.168.8.214
Host is up (0.088s latency).
Nmap scan report for 192.168.8.215
Host is up (0.083s latency).
Nmap scan report for 192.168.8.216
Host is up (0.087s latency).
Nmap scan report for 192.168.8.217
Host is up (0.10s latency).
Nmap scan report for 192.168.8.218
Host is up (0.10s latency).
Nmap scan report for 192.168.8.219
Host is up (0.0027s latency).
Nmap scan report for 192.168.8.220
Host is up (0.0062s latency).
Nmap scan report for 192.168.8.221
Host is up (0.10s latency).
Nmap scan report for 192.168.8.222
Host is up (0.10s latency).
Nmap scan report for 192.168.8.223
Host is up (0.088s latency).
Nmap scan report for 192.168.8.224
Host is up (0.088s latency).
Nmap scan report for 192.168.8.225
Host is up (0.014s latency).
Nmap scan report for 192.168.8.226
Host is up (0.094s latency).
Nmap scan report for 192.168.8.227
Host is up (0.083s latency).
Nmap scan report for 192.168.8.228
Host is up (0.088s latency).
Nmap scan report for 192.168.8.229
Host is up (0.013s latency).
Nmap scan report for 192.168.8.230
Host is up (0.088s latency).
Nmap scan report for 192.168.8.231
Host is up (0.0029s latency).
Nmap scan report for 192.168.8.232
Host is up (0.086s latency).
Nmap scan report for 192.168.8.233
Host is up (0.0037s latency).
Nmap scan report for 192.168.8.234
Host is up (0.0025s latency).
Nmap scan report for 192.168.8.235
Host is up (0.059s latency).
Nmap scan report for 192.168.8.236
Host is up (0.059s latency).
Nmap scan report for 192.168.8.237
Host is up (0.059s latency).
Nmap scan report for 192.168.8.238
Host is up (0.067s latency).
Nmap scan report for 192.168.8.239
Host is up (0.087s latency).
Nmap scan report for 192.168.8.240
Host is up (0.016s latency).
Nmap scan report for 192.168.8.241
Host is up (0.061s latency).
Nmap scan report for 192.168.8.242
Host is up (0.060s latency).
Nmap scan report for 192.168.8.243
Host is up (0.086s latency).
Nmap scan report for 192.168.8.244
Host is up (0.030s latency).
Nmap scan report for 192.168.8.245
Host is up (0.060s latency).
Nmap scan report for 192.168.8.246
Host is up (0.060s latency).
Nmap scan report for 192.168.8.247
Host is up (0.060s latency).
Nmap scan report for 192.168.8.248
Host is up (0.087s latency).
Nmap scan report for 192.168.8.249
Host is up (0.087s latency).
Nmap scan report for 192.168.8.250
Host is up (0.060s latency).
Nmap scan report for 192.168.8.251
Host is up (0.087s latency).
Nmap scan report for 192.168.8.252
Host is up (0.011s latency).
Nmap scan report for 192.168.8.253
Host is up (0.090s latency).
Nmap scan report for 192.168.8.254
Host is up (0.090s latency).
Nmap scan report for 192.168.8.255
Host is up (0.023s latency).
Nmap done: 256 IP addresses (256 hosts up) scanned in 4.72 seconds
可以看到共有256台主机是存活的。
如在我的虚拟机上,执行如下命令
[root@localhost ~]# nmap -sS 192.168.254.137
Starting Nmap 6.40 ( http://nmap.org ) at 2018-07-10 14:37 CST
Nmap scan report for 192.168.254.137
Host is up (0.0000090s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 0.16 seconds
可知我的22远程端口是开发的,并且我的80端口是开放的。使用netstat也可以查看到
[root@localhost ~]# netstat -ltpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 933/nginx: master p
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 913/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1029/master
tcp6 0 0 :::22 :::* LISTEN 913/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1029/master
默认扫描的端口是在0-1024,我们也可以加入-p参数扫描端口范围。
[root@localhost ~]# nmap -sS -p 0-30000 192.168.254.137
Starting Nmap 6.40 ( http://nmap.org ) at 2018-07-10 14:44 CST
Nmap scan report for 192.168.254.137
Host is up (0.0000090s latency).
Not shown: 29999 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 0.97 seconds
使用-sT参数可以更真实模拟TCP的三次握手请求,一般用时会更大些。而-sU则比较少用,而且跟linux内核有些不同,很多时候会等待很长时间。