gpt4 book ai didi

linux - Grep nmap 输出

转载 作者:太空宇宙 更新时间:2023-11-04 10:38:28 25 4
gpt4 key购买 nike

我已经将我的 nmap 结果输出到一个名为 test.txt 的文件中,它看起来像这样:

Nmap scan report for 192.168.1.5
Host is up (0.13s latency).
PORT STATE SERVICE VERSION
23/tcp open telnet Linux telnetd
--
Nmap scan report for 192.168.1.7
Host is up (0.13s latency).
PORT STATE SERVICE VERSION
80/tcp open http Popper
--
Nmap scan report for 192.168.1.20
Host is up (0.13s latency).
PORT STATE SERVICE VERSION
110/tcp open pop3 Dove

我想使用 grep 和管道从我的终端中的文件输出结果,以格式显示结果:IP 地址后跟打开的端口,如下所示:

192.168.10.2
80
223
53
192.168.10.7
80
223

最佳答案

你可能想要:

cat test.txt | sed 's/Nmap scan report for //' | sed '/Host is/d' | sed '/Not shown/d' | sed '/All/d' | sed '/PORT /d' | cut -f1 -d"/" | sed '/^$/d' | sed '/--/d'

对于 nmap -F 192.168.0.1/24 > test.txt:

cat test.txt | tail -n+3 | sed '/Nmap done/d' | awk 'NR>1{print l}{l=$0}' | sed 's/Nmap scan report for //' | sed '/Host is/d' | sed '/Not shown/d' | sed '/All/d' | sed '/PORT /d' | cut -f1 -d"/" | sed '/^$/d'

笑话。这没有意义...使用 nmap 和 XML 输出 -oX
阅读:https://nmap.org/book/output-formats-xml-output.html

关于linux - Grep nmap 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36252194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com