核心内容
grep -v down
-v 是不显示匹配上的内容 ,显示不包含down的内容。
需求引入
做主机扫描的时候,方便查看在线的主机
dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24
dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24
Nmap scan report for 192.168.1.0 [host down]
Nmap scan report for 192.168.1.1 Host is up (0.0021s latency).
Nmap scan report for 192.168.1.2 [host down]
Nmap scan report for 192.168.1.3 [host down]
……
Nmap scan report for 192.168.1.98 [host down]
Nmap scan report for 192.168.1.99 [host down]
Nmap scan report for 192.168.1.100 Host is up (0.084s latency).
Nmap scan report for 192.168.1.101 [host down]
Nmap scan report for 192.168.1.102 Host is up (0.062s latency).
Nmap scan report for 192.168.1.103 Host is up (0.0060s latency).
Nmap scan report for 192.168.1.104 [host down]
Nmap scan report for 192.168.1.105 Host is up (0.10s latency).
Nmap scan report for 192.168.1.106 Host is up (0.00092s latency).
Nmap scan report for 192.168.1.107 [host down]
Nmap scan report for 192.168.1.108 [host down]
…….
Nmap scan report for 192.168.1.254 [host down]
Nmap scan report for 192.168.1.255 [host down]
Read data files from: /usr/bin/../share/nmap
Nmap done: 256 IP addresses (6 hosts up) scanned in 4.28 seconds
如果只是显示up的行,没有想要的Ip 地址
dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24 | grep up
dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24 | grep up
Host is up (0.0034s latency).
Host is up (0.021s latency).
Host is up (0.16s latency).
Host is up (0.012s latency).
Host is up (0.035s latency).
Host is up (0.0056s latency).
Host is up (0.0012s latency).
Nmap done: 256 IP addresses (7 hosts up) scanned in 3.63 seconds
所以过滤掉down是个不错的选择, -v 是不显示匹配上的内容
dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24 | grep -v down
dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24 | grep -v down
Starting Nmap 7.01 ( https://nmap.org ) at 2016-10-28 00:57 CST
Initiating Ping Scan at 00:57
Nmap scan report for 192.168.1.1
Host is up (0.0039s latency).
Nmap scan report for 192.168.1.100
Host is up (0.014s latency).
Nmap scan report for 192.168.1.101
Host is up (0.061s latency).
Nmap scan report for 192.168.1.103
Host is up (0.013s latency).
Nmap scan report for 192.168.1.105
Host is up (0.0090s latency).
Nmap scan report for 192.168.1.106
Host is up (0.000086s latency).
Read data files from: /usr/bin/../share/nmap
Nmap done: 256 IP addresses (6 hosts up) scanned in 2.96 seconds
趋于完美,但是还是有很多无用信息,进一步过滤.
dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24 | grep -v down | grep 192
dotheright@dotheright:~$ nmap -v -sn 192.168.1.1/24 | grep -v down | grep 192
Nmap scan report for 192.168.1.1
Nmap scan report for 192.168.1.100
Nmap scan report for 192.168.1.101
Nmap scan report for 192.168.1.103
Nmap scan report for 192.168.1.104
Nmap scan report for 192.168.1.105
Nmap scan report for 192.168.1.106