我已经使用这个小脚本几个月了,现在已经成功了。今天,我意识到有一个输出似乎无法捕捉,屏幕空白并显示新的提示符:
user@computer ~]$ myscan ipsFile 23
user@computer ~]$以下是代码
#!/bin/bash
sudo nmap -v -Pn -p T:$2 -reason -i $1 | awk ' {
if (/syn-ack/) {
print "Yes"
c++
}
else if (/no-response|reset|host-unreach/) {
print "No"
c++
}
}
END { print c} '如果我对其中一个it运行nmap,则它将返回
Starting Nmap 5.51 ( http://nmap.org ) at 2017-09-26 11:44 CDT
Initiating Parallel DNS resolution of 1 host. at 11:44
Completed Parallel DNS resolution of 1 host. at 11:44, 0.00s elapsed
Initiating Connect Scan at 11:44
Scanning 1.1.1.1 [1 port]
Completed Connect Scan at 11:44, 0.20s elapsed (1 total ports)
Nmap scan report for 1.1.1.1
Host is up, received user-set (0.20s latency).
PORT STATE SERVICE REASON
23/tcp filtered telnet host-unreach
Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds如何捕获“主机未到达”部分?
发布于 2017-09-27 03:51:00
让我们试着调试一下。执行以下命令:
nmap -v -Pn -p T:23 -reason -i ipsFile | awk '{print $0}/syn-ack/{print "Yes";c++}/no-response|reset|host-unreach/{print "No";c++}END {print c}' > out.txt这里唯一的区别是awk脚本将$0 (即nmap调用的输出)打印到文件out.txt。尝试grep您的unreach值。
我自己试了试,发现我得到的不是host-unreach,而是net-unreach。你的情况可能也是一样。
发布于 2017-09-27 01:03:25
您是否尝试过将stderr转换为stdout,如下所示
#!/bin/bash
sudo nmap -v -Pn -p T:$2 -reason -i $1 2>&1 | awk ' {
if (/syn-ack/) {
print "Yes"
c++
}
else if (/no-response|reset|host-unreach/) {
print "No"
c++
}
}
END { print c} 'https://stackoverflow.com/questions/46432037
复制相似问题