grep 搜索不包含关键字的行

核心内容

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值