我正在尝试自动执行某些安全网络任务,以帮助我完成日常工作,并遇到了以下问题。
我有代码:
OSNmapScanCommand="nmap -nvv -Pn -O --osscan-guess --defeat-rst-ratelimit " + IP + " | grep \"Device type:\" -A4 > "+ MyFile
subprocess.check_output(OSNmapScanCommand, cwd=CurrentHost, shell=True)
由于某些原因,它在某些主机上工作正常,但在其他一些主机上,我得到nmap输出文本,我相信只会在我的脚本停止运行的情况下触发错误:
adjust_timeouts2: packet supposedly had rtt of -161442 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -161442 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -1384846 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -1384846 microseconds. Ignoring time.
Traceback (most recent call last):
File "nmap.py", line 152, in <module>
subprocess.check_output(OSNmapScanCommand, cwd=CurrentHost, shell=True)
File "/usr/lib/python2.7/subprocess.py", line 219, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command 'nmap -nvv -Pn -O --osscan-guess --defeat-rst-ratelimit xx.xx.xx.xx | grep "Device type:" -A4 > myfile.txt' returned non-zero exit status 1
我已经使用subprocess.check_output和subprocess.check_call编写了一个很长的脚本脚本而没有问题,但我仍然坚持这个。
感谢您的帮助!
[编辑]如果我单独运行nmap命令,这就是我得到的:
adjust_timeouts2: packet supposedly had rtt of -164659 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -164659 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -1395479 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -1395479 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -1396430 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -1396430 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -1396454 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -1396454 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -90623 microseconds. Ignoring time.
adjust_timeouts2: packet supposedly had rtt of -90623 microseconds. Ignoring time.
Device type: general purpose|switch|printer|firewall|security-misc|WAP|remote management|specialized
Running (JUST GUESSING): Linux 2.6.X|2.4.X (95%), Extreme Networks ExtremeXOS 12.X (93%), Kyocera embedded (93%), Barracuda Networks embedded (93%), AVM embedded (90%), Linksys embedded (90%), Netgear embedded (90%), Dell embedded (90%)
OS CPE: cpe:/o:linux:linux_kernel:2.6 cpe:/o:extremenetworks:extremexos:12.5.4 cpe:/h:kyocera:cs-2560 cpe:/h:avm:fritz%21box_fon_wlan_7050 cpe:/h:linksys:wag200g cpe:/h:netgear:dg834gt cpe:/h:dell:remote_access_card:5 cpe:/o:linux:linux_kernel:2.4.21
Aggressive OS guesses: Linux 2.6.15 - 2.6.26 (likely embedded) (95%), Linux 2.6.16 (94%), Extreme Networks ExtremeXOS 12.5.4 (93%), Kyocera CopyStar CS-2560 printer (93%), Linux 2.6.15 (Ubuntu) (93%), Linux 2.6.26 (93%), Barracuda Web Application Firewall 460 (93%), Linux 2.6.32 (93%), Barracuda Web Filter (92%), Linux 2.6.22 (92%)
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
所以我认为错误来自于我如何使用subprocess.check_output?