pyshark

Using Pyshark to pair key and value from JSON packet

随声附和 提交于 2020-08-11 01:43:20
问题 I am trying to parse a PCAP file using Pyshark. Some of the packets have JSON in them and I am trying to print them out with matching key:value. This is what I have at the moment for testing: import pyshark packets = pyshark.FileCapture('cap.pcapng') pack = packets[1] #get the packet that has JSON print(pack.json.get_field_value('app') When doing this, I get None printed. If I print the entire JSON layer I get data like this: Object Member Key: anonymousId String value: f268204c-5719-43ce

Count the number of packets with pyshark

家住魔仙堡 提交于 2020-03-22 10:01:36
问题 In this code with pyshark import pyshark cap = pyshark.FileCapture(filename) i = 0 for idx, packet in enumerate(cap): i += 1 print i print len(cap._packets) i and len(cap._packets) give two different results. Why is that? 回答1: A look at the source code reveals that _packets is a list containing packets and is only used internally: When iterating through a FileCapture object with keep_packets = True packets are getting added to this list. To get access to all packets in a FileCapture object

OSX PyShark: RuntimeWarning: coroutine 'wait_for' was never awaited

醉酒当歌 提交于 2019-12-24 02:14:58
问题 I was wondering if anyone around here might know what causes this issue. I keep getting this error on OSX High Sierra, while running a python script which uses the pyshark library. I am running Tshark 2.6.2 Python 3.7.0 PyShark 0.4.1 The error: /usr/local/lib/python3.7/site-packages/pyshark-0.4.1-py3.7.egg/pyshark/capture/capture.py:230: RuntimeWarning: coroutine 'wait_for' was never awaited self.eventloop.run_until_complete(self._cleanup_subprocess(tshark_process)) /usr/local/lib/python3.7

Pyshark: can only get first field value if same key name (field name) show multiple entries with different value

好久不见. 提交于 2019-12-23 18:11:10
问题 I am using Pyshark to parse Wireshark sniffer log, and I used exported Json format file (based on pcapny file) to find field names when use 'get_field_value' function to retrieve field value. For example, in order to get BSSID value: In Json format file, this info is displayed as "wlan.bssid": "11:22:33:44:55:66" Then I could use: value = packet['wlan'].get_field_value('bssid') Result is expected: value == '11:22:33:44:55:66' For this case, it is working fine. But I encounter an issue with

pyshark can not capture the packet on windows 7 (python)

时光怂恿深爱的人放手 提交于 2019-12-23 09:48:33
问题 I want to capture the packet using pyshark. but I could not capture the packet on windows 7. this is my python code import pyshark def NetCap(): print 'capturing...' livecapture = pyshark.LiveCapture(interface="eth0", output_file='./test.pcapng') livecapture.sniff(packet_count=10) print 'end of capture.' print livecapture if __name__ == "__main__": NetCap() this is result capturing... end of capture. <LiveCapture (0 packets)> Livecapture is 0 packets. I don't know what is the matter. please

How to send a pyshark packet to specific network interface?

白昼怎懂夜的黑 提交于 2019-12-08 06:32:23
I am able to read a packet from .pcap file using pyshark . Here is my code: import pyshark cap = pyshark.FileCapture(pcap_dir) # pcap_dir is the directory of my pcap file print(cap[0]) # Print a packet print(cap[0]['IP'].src) # Print some header value Now, I need to send this packet to some interface (e.g. eth0 ). I tried the follwoing: from socket import socket, AF_PACKET, SOCK_RAW sock = socket(AF_PACKET, SOCK_RAW) sock.bind(('eth0', 0)) sock.send(cap[0]) But I get the error: sock.send(cap[0]) TypeError: a bytes-like object is required, not 'Packet' Can anyone help? I was able to solve my

How to send a pyshark packet to specific network interface?

你。 提交于 2019-12-08 05:11:27
问题 I am able to read a packet from .pcap file using pyshark . Here is my code: import pyshark cap = pyshark.FileCapture(pcap_dir) # pcap_dir is the directory of my pcap file print(cap[0]) # Print a packet print(cap[0]['IP'].src) # Print some header value Now, I need to send this packet to some interface (e.g. eth0 ). I tried the follwoing: from socket import socket, AF_PACKET, SOCK_RAW sock = socket(AF_PACKET, SOCK_RAW) sock.bind(('eth0', 0)) sock.send(cap[0]) But I get the error: sock.send(cap