python pycharm (using pyshark library)
如何在pycharm上的pc项目文件中添加pcap文件?
这是我的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import pyshark cap = pyshark.FileCapture('dnpdataset') def print_conversation_header(pkt): try: protocol = pkt.transport_layer src_addr = pkt.ip.src src_port = pkt[pkt.transport_layer].srcport dst_addr = pkt.ip.dst dst_port = pkt[pkt.transport_layer].dstport '%s %s:%s --> %s:%s' % (protocol, src_addr, src_port, dst_addr, dst_port) except AttributeError as e: # ignore packets that aren't TCP/UDP or IPv4 pass cap.apply_on_packets(print_conversation_header, timeout=100) |
给我这个错误:
Traceback (most recent call last): File
"C:/Users/mtare/PycharmProjects/moe1/first.py", line 3, in
cap = pyshark.FileCapture('dnpdataset') File"C:\Users\mtare\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyshark\capture\file_capture.py",
line 47, in init
raise FileNotFoundError(str(self.input_filename)) FileNotFoundError: dnpdataset
您必须为FileCapture提供捕获文件的绝对路径
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import pyshark cap = pyshark.FileCapture(r'C:\Temp\dnpdataset.pcap') def print_conversation_header(pkt): try: protocol = pkt.transport_layer src_addr = pkt.ip.src src_port = pkt[pkt.transport_layer].srcport dst_addr = pkt.ip.dst dst_port = pkt[pkt.transport_layer].dstport print('%s %s:%s --> %s:%s' % (protocol, src_addr, src_port, dst_addr, dst_port)) except AttributeError as e: # ignore packets that aren't TCP/UDP or IPv4 pass cap.apply_on_packets(print_conversation_header, timeout=100) |