【发布时间】:2020-04-20 12:39:15
【问题描述】:
我正在尝试嗅探现有的 pcap 文件,对其进行过滤并将其保存到一个新文件中,但是当我运行我的代码时会弹出此异常。 我该如何解决这个问题?
代码:
from scapy.all import *
def write(pcap):
for pkt in pcap:
wrpcap('filtered.pcap', pkt, append=True)
else:
pass
def load_pcap(path, filter_str):
pcap = sniff(offline=path, filter=filter_str)
write(pcap)
def main():
load_pcap("file.pcap", 'icmp')
main()
例外:
Traceback (most recent call last):
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37\lib\site-packages\scapy\utils.py", line 1663, in tcpdump
stderr=stderr,
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1100, in _execute_child
args = list2cmdline(args)
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 511, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'NoneType' is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "sharkscript.py", line 140, in <module>
main()
File "sharkscript.py", line 137, in main
funcs()
File "sharkscript.py", line 130, in funcs
options()
File "sharkscript.py", line 95, in options
load_pcap(get_filter(), path)
File "sharkscript.py", line 33, in load_pcap
pcap = sniff(offline=path, filter=filter_str)
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37\lib\site-packages\scapy\sendrecv.py", line 972, in sniff
sniffer._run(*args, **kwargs)
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37\lib\site-packages\scapy\sendrecv.py", line 824, in _run
)] = offline
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37\lib\site-packages\scapy\utils.py", line 1663, in tcpdump
stderr=stderr,
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37\lib\site-packages\scapy\utils.py", line 555, in __exit__
raise OSError(msg)
OSError: Could not execute windump(), is it installed ?
我尝试搜索 windump 以及如何安装它,但找不到任何东西。 是否有另一种过滤“离线”pcap 的方法?
【问题讨论】:
标签: python scapy pcap packet-sniffers sniffing