尝试将nmap结果保存到txt文件

时间:2018-12-30 13:22:32

标签: bash output nmap

我尝试将nmap扫描的结果保存到txt文件中。我使用此命令

nmap -n -Pn -p T:3389 -T5 -sS -iR 0 | grep "scan" | awk '{ print $5 }' > test.txt

cat test.txt

输出看起来像这样:

xx.xx.xx.xx
xx.xx.xx.xx
xx.xx.xx.xx
xx.xx.xx.xx
xx.xx.xx.xx
xx.xx.xx.xx

运行正常。

我只想扫描打开的端口,为此,我尝试使用--open这样的选项:

nmap -n -Pn -p T:3389 --open -T5 -sS -iR 0 | grep "scan" | awk '{ print $5 }' > test.txt

它不起作用,test.txt为空。我尝试使用tail -f test.txt查看实时结果,但是无法正常工作。有人可以解释我在做什么,对吗?

我期望第一次看到结果。

xx.xx.xx.xx
xx.xx.xx.xx
xx.xx.xx.xx
xx.xx.xx.xx
xx.xx.xx.xx
xx.xx.xx.xx

我想在所有IP之后添加端口号

xx.xx.xx.xx:3389
xx.xx.xx.xx:3389
xx.xx.xx.xx:3389
xx.xx.xx.xx:3389
xx.xx.xx.xx:3389
xx.xx.xx.xx:3389

为此,我想使用sed -i s/$/:3389/ test.txt

我想知道是否有可能仅用一个命令就能得到这个结果。

我尝试这样的事情:

nmap -n -Pn -p T:3389 --open -T5 -sS 192.168.0.1/24 | grep "scan" | awk '{ print $5 }' > test.txt; sed -i s/$/:3389/ test.txt

cat test.txt,这就是结果:

192.168.0.2:3389
192.168.0.16:3389
addresses:3389

我不知道为什么地址:3389会出现在末尾。但这有效。

我想得到相同的结果,但是使用以下命令:

nmap -n -Pn -p T:3389 --open -T5 -sS -iR 0 | grep "scan" | awk '{ print $5 }' > test.txt; sed -i s/$/:3389/ test.txt

我尝试使用此命令,但不起作用。我想在bash脚本中使用此命令。任何帮助或建议,我们都会感激不尽。

nmap -n -Pn -p T:3389 --open -T5 -sS -iR 0

这是输出:

    Nmap scan report for 187.3.104.223
    Host is up (0.29s latency).

    PORT     STATE SERVICE
    3389/tcp open  ms-wbt-server

    Nmap scan report for 118.89.215.203
    Host is up (0.29s latency).

    PORT     STATE SERVICE
    3389/tcp open  ms-wbt-server

2 个答案:

答案 0 :(得分:0)

“地址”来自Nmap输出的摘要结尾行,第5个字:

   Nmap done: 256 IP addresses (10 hosts up) scanned in 3.12 seconds

要从输出中删除地址,请执行以下操作:

   nmap -n -Pn -p T:3389 --open -T5 -sS -iR 0 |grep scan|grep -v addresses|awk '{print $5}' | sed 's/$/:3389/' > test.txt

如果不是您期望的/想要得到的输出,请发布您的输出

答案 1 :(得分:0)

我找到了使之工作的方法。这是命令:

nmap -n -Pn -p T:3389 -T5 -sS -iR 5000 --open | grep scan | grep -v addresses | awk '{print $5}' | sed 's/$/:3389/' > test

cat test

输出:

35.190.27.36:3389
35.214.139.176:3389
132.190.70.226:3389
109.228.13.61:3389
103.10.175.4:3389
113.134.99.14:3389
35.168.9.215:3389
167.93.112.130:3389
115.220.6.216:3389
137.32.209.1:3389
35.206.198.136:3389

如果需要,我可以更改-iR 5000,但仍然可以使用。不适用于0

如果有人需要,我希望能有所帮助。谢谢大家

相关问题