【发布时间】:2013-12-11 20:01:19
【问题描述】:
我使用 NMAP,在大型网络上运行扫描以查看打开的端口。输出文件为 2MB,但我想过滤掉所有关闭端口的所有 IP 地址。
Nmap scan report for 10.x.x.x
Host is up (0.048s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
23/tcp open telnet
Nmap scan report for 10.x.x.x
Host is up (0.046s latency).
All 1000 scanned ports on 10.x.x.x are closed
Nmap scan report for 10.x.x.x
Host is up (0.045s latency).
All 1000 scanned ports on 10.x.x.x are closed
应该输出到只输出到:
Nmap scan report for 10.x.x.x
Host is up (0.048s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
23/tcp open telnet
编辑
结果是这样的
Nmap scan report for 10.x.x.x
Host is up (0.048s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
23/tcp open telnet
Nmap scan report for 10.x.x.x
Host is up (0.046s latency).
All 1000 scanned ports on 10.x.x.x are closed
Nmap scan report for 10.x.x.x
Host is up (0.045s latency).
All 1000 scanned ports on 10.x.x.x are closed
有些换行符没有正确复制
编辑 感谢大家。我看到 awk 非常棒,而且很容易做到。
【问题讨论】:
-
我只知道简单的 grep。比如“cat nmap,out | grep open”。但它只列出了打开的端口,而不列出其他详细信息,例如 ip 地址
-
请提供您正在使用的 nmap 命令行,以便我们复制您的输出以测试解决方案。
-
好的。除了前面评论中提到的简单 grep 之外,您还尝试过什么?
-
这是唯一的事情。我不知道如何让 grep 抓取其他需要的行,例如具有开放端口的主机的主机 IP 地址,同时过滤掉具有所有关闭端口的主机的 IP 地址和信息。