Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-pyshark for openSUSE:Factory checked in at 2021-03-11 20:10:19 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-pyshark (Old) and /work/SRC/openSUSE:Factory/.python-pyshark.new.2401 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-pyshark" Thu Mar 11 20:10:19 2021 rev:2 rq:877414 version:0.4.3 Changes: -------- --- /work/SRC/openSUSE:Factory/python-pyshark/python-pyshark.changes 2019-10-28 16:59:13.373675415 +0100 +++ /work/SRC/openSUSE:Factory/.python-pyshark.new.2401/python-pyshark.changes 2021-03-11 20:12:32.456687817 +0100 @@ -1,0 +2,6 @@ +Sat Mar 6 13:09:44 UTC 2021 - Martin Hauke <mar...@gmx.de> + +- Update to version 0.4.3 + * Upstream does not provide a changelog + +------------------------------------------------------------------- Old: ---- v0.4.2.11.tar.gz New: ---- v0.4.3.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-pyshark.spec ++++++ --- /var/tmp/diff_new_pack.8iOmQD/_old 2021-03-11 20:12:33.176688985 +0100 +++ /var/tmp/diff_new_pack.8iOmQD/_new 2021-03-11 20:12:33.180688991 +0100 @@ -1,8 +1,8 @@ # # spec file for package python-pyshark # -# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. -# Copyright (c) 2019, Martin Hauke <mar...@gmx.de> +# Copyright (c) 2021 SUSE LLC +# Copyright (c) 2019-2021, Martin Hauke <mar...@gmx.de> # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -20,7 +20,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} %define skip_python2 1 Name: python-pyshark -Version: 0.4.2.11 +Version: 0.4.3 Release: 0 Summary: A Python wrapper for tshark output parsing License: MIT ++++++ v0.4.2.11.tar.gz -> v0.4.3.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/.travis.yml new/pyshark-0.4.3/.travis.yml --- old/pyshark-0.4.2.11/.travis.yml 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/.travis.yml 2021-02-06 08:44:25.000000000 +0100 @@ -1,8 +1,10 @@ -dist: trusty +dist: bionic language: python python: - "3.5" - "3.6" + - "3.7" + - "3.8" before_install: - sudo apt-get update -qq - sudo apt-get install -y tshark diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/README.md new/pyshark-0.4.3/README.md --- old/pyshark-0.4.2.11/README.md 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/README.md 2021-02-06 08:44:25.000000000 +0100 @@ -1,236 +1,246 @@ -# pyshark - -[](https://gitter.im/pyshark_gitter/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://travis-ci.org/KimiNewt/pyshark) - -Python wrapper for tshark, allowing python packet parsing using wireshark dissectors. - -Extended documentation: http://kiminewt.github.io/pyshark - -**Python2 deprecation** - This package no longer supports Python2. If you wish to still use it in Python2, you can: -* Use version 0.3.8 -* Install pyshark-legacy via pypi -* Clone the pyshark-legacy [repo (https://github.com/KimiNewt/pyshark-legacy)], where bugfixes will be applied. - -**Looking for contributors** - for various reasons I have a hard time finding time to maintain and enhance the package at the moment. Any pull-requests will be reviewed and if any one is interested and is suitable, I will be happy to include them in the project. Feel free to mail me at dorgreen1 at gmail. - -There are quite a few python packet parsing modules, this one is different because it doesn't actually parse any packets, it simply uses tshark's (wireshark command-line utility) ability to export XMLs to use its parsing. - -This package allows parsing from a capture file or a live capture, using all wireshark dissectors you have installed. -Tested on windows/linux. - -## Installation - -### All Platforms -Simply run the following to install the latest from pypi -```bash -pip install pyshark -``` - -Or install from the git repository: -```bash -git clone https://github.com/KimiNewt/pyshark.git -cd pyshark/src -python setup.py install -``` - - -### Mac OS X -You may have to install libxml which can be unexpected. If you receive an error from clang or an error message about libxml, run the following: -```bash -xcode-select --install -pip install libxml -``` -You will probably have to accept a EULA for XCode so be ready to click an "Accept" dialog in the GUI. - - - -## Usage - -### Reading from a capture file: - -```python ->>> import pyshark ->>> cap = pyshark.FileCapture('/tmp/mycapture.cap') ->>> cap -<FileCapture /tmp/mycapture.cap (589 packets)> ->>> print cap[0] -Packet (Length: 698) -Layer ETH: - Destination: BLANKED - Source: BLANKED - Type: IP (0x0800) -Layer IP: - Version: 4 - Header Length: 20 bytes - Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport)) - Total Length: 684 - Identification: 0x254f (9551) - Flags: 0x00 - Fragment offset: 0 - Time to live: 1 - Protocol: UDP (17) - Header checksum: 0xe148 [correct] - Source: BLANKED - Destination: BLANKED - ... -``` - -#### Other options - -* **param keep_packets**: Whether to keep packets after reading them via next(). -Used to conserve memory when reading large caps. -* **param input_file**: Either a path or a file-like object containing either a -packet capture file (PCAP, PCAP-NG..) or a TShark xml. -* **param display_filter**: A display (wireshark) filter to apply on the cap -before reading it. -* **param only_summaries**: Only produce packet summaries, much faster but includes -very little information -* **param disable_protocol**: Disable detection of a protocol (tshark > version 2) -* **param decryption_key**: Key used to encrypt and decrypt captured traffic. -* **param encryption_type**: Standard of encryption used in captured traffic (must -be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK. -* **param tshark_path**: Path of the tshark binary - -### Reading from a live interface: - -```python ->>> capture = pyshark.LiveCapture(interface='eth0') ->>> capture.sniff(timeout=50) ->>> capture -<LiveCapture (5 packets)> ->>> capture[3] -<UDP/HTTP Packet> - -for packet in capture.sniff_continuously(packet_count=5): - print 'Just arrived:', packet -``` - -#### Other options - -* **param interface**: Name of the interface to sniff on. If not given, takes -the first available. -* **param bpf_filter**: BPF filter to use on packets. -* **param display_filter**: Display (wireshark) filter to use. -* **param only_summaries**: Only produce packet summaries, much faster but -includes very little information -* **param disable_protocol**: Disable detection of a protocol (tshark > version 2) -* **param decryption_key**: Key used to encrypt and decrypt captured traffic. -* **param encryption_type**: Standard of encryption used in captured traffic -(must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK). -* **param tshark_path**: Path of the tshark binary -* **param output_file**: Additionally save captured packets to this file. - -### Reading from a live interface using a ring buffer -```python ->>> capture = pyshark.LiveRingCapture(interface='eth0') ->>> capture.sniff(timeout=50) ->>> capture -<LiveCapture (5 packets)> ->>> capture[3] -<UDP/HTTP Packet> - -for packet in capture.sniff_continuously(packet_count=5): - print 'Just arrived:', packet -``` - -#### Other options -* **param ring_file_size**: Size of the ring file in kB, default is 1024 -* **param num_ring_files**: Number of ring files to keep, default is 1 -* **param ring_file_name**: Name of the ring file, default is /tmp/pyshark.pcap -* **param interface**: Name of the interface to sniff on. If not given, takes -the first available. -* **param bpf_filter**: BPF filter to use on packets. -* **param display_filter**: Display (wireshark) filter to use. -* **param only_summaries**: Only produce packet summaries, much faster but -includes very little information -* **param disable_protocol**: Disable detection of a protocol (tshark > version 2) -* **param decryption_key**: Key used to encrypt and decrypt captured traffic. -* **param encryption_type**: Standard of encryption used in captured traffic -(must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK). -* **param tshark_path**: Path of the tshark binary -* **param output_file**: Additionally save captured packets to this file. - -### Reading from a live remote interface: - -```python ->>> capture = pyshark.RemoteCapture('192.168.1.101', 'eth0') ->>> capture.sniff(timeout=50) ->>> capture -``` - -#### Other options - -* **param remote_host**: The remote host to capture on (IP or hostname). -Should be running rpcapd. -* **param remote_interface**: The remote interface on the remote machine to -capture on. Note that on windows it is not the device display name but the -true interface name (i.e. \\Device\\NPF_..). -* **param remote_port**: The remote port the rpcapd service is listening on -* **param bpf_filter**: A BPF (tcpdump) filter to apply on the cap before -reading. -* **param only_summaries**: Only produce packet summaries, much faster but -includes very little information -* **param disable_protocol**: Disable detection of a protocol (tshark > version 2) -* **param decryption_key**: Key used to encrypt and decrypt captured traffic. -* **param encryption_type**: Standard of encryption used in captured traffic -(must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK). -* **param tshark_path**: Path of the tshark binary - -### Accessing packet data: - -Data can be accessed in multiple ways. -Packets are divided into layers, first you have to reach the appropriate layer and then you can select your field. - -All of the following work: - -```python ->>> packet['ip'].dst -192.168.0.1 ->>> packet.ip.src -192.168.0.100 ->>> packet[2].src -192.168.0.100 -``` - -To test whether a layer is in a packet, you can use its name: - -```python ->>> 'IP' in packet -True -``` - -To see all possible field names, use the `packet.layer.field_names` attribute (i.e. `packet.ip.field_names`) or the autocomplete function on your interpreter. - -You can also get the original binary data of a field, or a pretty description of it: - -```python ->>> p.ip.addr.showname -Source or Destination Address: 10.0.0.10 (10.0.0.10) -# And some new attributes as well: ->>> p.ip.addr.int_value -167772170 ->>> p.ip.addr.binary_value -'\n\x00\x00\n' -``` - - -### Decrypting packet captures - -Pyshark supports automatic decryption of traces using the WEP, WPA-PWD, and WPA-PSK standards (WPA-PWD is the default). - -```python ->>> cap1 = pyshark.FileCapture('/tmp/capture1.cap', decryption_key='password') ->>> cap2 = pyshark.LiveCapture(interface='wi0', decryption_key='password', encryption_type='wpa-psk') -``` - -A tuple of supported encryption standards, SUPPORTED_ENCRYPTION_STANDARDS, -exists in each capture class. - -```python ->>> pyshark.FileCapture.SUPPORTED_ENCRYPTION_STANDARDS -('wep', 'wpa-pwd', 'wpa-psk') ->>> pyshark.LiveCapture.SUPPORTED_ENCRYPTION_STANDARDS -('wep', 'wpa-pwd', 'wpa-psk') -``` -## License -This project is licensed under MIT. Contributions to this project are accepted under the same license. +# pyshark + +[](https://gitter.im/pyshark_gitter/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://travis-ci.org/KimiNewt/pyshark) + +Python wrapper for tshark, allowing python packet parsing using wireshark dissectors. + +Extended documentation: http://kiminewt.github.io/pyshark + +**Python2 deprecation** - This package no longer supports Python2. If you wish to still use it in Python2, you can: +* Use version 0.3.8 +* Install pyshark-legacy via pypi +* Clone the pyshark-legacy [repo (https://github.com/KimiNewt/pyshark-legacy)], where bugfixes will be applied. + +**Looking for contributors** - for various reasons I have a hard time finding time to maintain and enhance the package at the moment. Any pull-requests will be reviewed and if any one is interested and is suitable, I will be happy to include them in the project. Feel free to mail me at dorgreen1 at gmail. + +There are quite a few python packet parsing modules, this one is different because it doesn't actually parse any packets, it simply uses tshark's (wireshark command-line utility) ability to export XMLs to use its parsing. + +This package allows parsing from a capture file or a live capture, using all wireshark dissectors you have installed. +Tested on windows/linux. + +## Installation + +### All Platforms +Simply run the following to install the latest from pypi +```bash +pip install pyshark +``` + +Or install from the git repository: +```bash +git clone https://github.com/KimiNewt/pyshark.git +cd pyshark/src +python setup.py install +``` + + +### Mac OS X +You may have to install libxml which can be unexpected. If you receive an error from clang or an error message about libxml, run the following: +```bash +xcode-select --install +pip install libxml +``` +You will probably have to accept a EULA for XCode so be ready to click an "Accept" dialog in the GUI. + + + +## Usage + +### Reading from a capture file: + +```python +>>> import pyshark +>>> cap = pyshark.FileCapture('/tmp/mycapture.cap') +>>> cap +<FileCapture /tmp/mycapture.cap (589 packets)> +>>> print cap[0] +Packet (Length: 698) +Layer ETH: + Destination: BLANKED + Source: BLANKED + Type: IP (0x0800) +Layer IP: + Version: 4 + Header Length: 20 bytes + Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport)) + Total Length: 684 + Identification: 0x254f (9551) + Flags: 0x00 + Fragment offset: 0 + Time to live: 1 + Protocol: UDP (17) + Header checksum: 0xe148 [correct] + Source: BLANKED + Destination: BLANKED + ... +``` + +#### Other options + +* **param keep_packets**: Whether to keep packets after reading them via next(). +Used to conserve memory when reading large caps. +* **param input_file**: Either a path or a file-like object containing either a +packet capture file (PCAP, PCAP-NG..) or a TShark xml. +* **param display_filter**: A display (wireshark) filter to apply on the cap +before reading it. +* **param only_summaries**: Only produce packet summaries, much faster but includes +very little information +* **param disable_protocol**: Disable detection of a protocol (tshark > version 2) +* **param decryption_key**: Key used to encrypt and decrypt captured traffic. +* **param encryption_type**: Standard of encryption used in captured traffic (must +be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK. +* **param tshark_path**: Path of the tshark binary + +### Reading from a live interface: + +```python +>>> capture = pyshark.LiveCapture(interface='eth0') +>>> capture.sniff(timeout=50) +>>> capture +<LiveCapture (5 packets)> +>>> capture[3] +<UDP/HTTP Packet> + +for packet in capture.sniff_continuously(packet_count=5): + print 'Just arrived:', packet +``` + +#### Other options + +* **param interface**: Name of the interface to sniff on. If not given, takes +the first available. +* **param bpf_filter**: BPF filter to use on packets. +* **param display_filter**: Display (wireshark) filter to use. +* **param only_summaries**: Only produce packet summaries, much faster but +includes very little information +* **param disable_protocol**: Disable detection of a protocol (tshark > version 2) +* **param decryption_key**: Key used to encrypt and decrypt captured traffic. +* **param encryption_type**: Standard of encryption used in captured traffic +(must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK). +* **param tshark_path**: Path of the tshark binary +* **param output_file**: Additionally save captured packets to this file. + +### Reading from a live interface using a ring buffer +```python +>>> capture = pyshark.LiveRingCapture(interface='eth0') +>>> capture.sniff(timeout=50) +>>> capture +<LiveCapture (5 packets)> +>>> capture[3] +<UDP/HTTP Packet> + +for packet in capture.sniff_continuously(packet_count=5): + print 'Just arrived:', packet +``` + +#### Other options +* **param ring_file_size**: Size of the ring file in kB, default is 1024 +* **param num_ring_files**: Number of ring files to keep, default is 1 +* **param ring_file_name**: Name of the ring file, default is /tmp/pyshark.pcap +* **param interface**: Name of the interface to sniff on. If not given, takes +the first available. +* **param bpf_filter**: BPF filter to use on packets. +* **param display_filter**: Display (wireshark) filter to use. +* **param only_summaries**: Only produce packet summaries, much faster but +includes very little information +* **param disable_protocol**: Disable detection of a protocol (tshark > version 2) +* **param decryption_key**: Key used to encrypt and decrypt captured traffic. +* **param encryption_type**: Standard of encryption used in captured traffic +(must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK). +* **param tshark_path**: Path of the tshark binary +* **param output_file**: Additionally save captured packets to this file. + +### Reading from a live remote interface: + +```python +>>> capture = pyshark.RemoteCapture('192.168.1.101', 'eth0') +>>> capture.sniff(timeout=50) +>>> capture +``` + +#### Other options + +* **param remote_host**: The remote host to capture on (IP or hostname). +Should be running rpcapd. +* **param remote_interface**: The remote interface on the remote machine to +capture on. Note that on windows it is not the device display name but the +true interface name (i.e. \\Device\\NPF_..). +* **param remote_port**: The remote port the rpcapd service is listening on +* **param bpf_filter**: A BPF (tcpdump) filter to apply on the cap before +reading. +* **param only_summaries**: Only produce packet summaries, much faster but +includes very little information +* **param disable_protocol**: Disable detection of a protocol (tshark > version 2) +* **param decryption_key**: Key used to encrypt and decrypt captured traffic. +* **param encryption_type**: Standard of encryption used in captured traffic +(must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK). +* **param tshark_path**: Path of the tshark binary + +### Accessing packet data: + +Data can be accessed in multiple ways. +Packets are divided into layers, first you have to reach the appropriate layer and then you can select your field. + +All of the following work: + +```python +>>> packet['ip'].dst +192.168.0.1 +>>> packet.ip.src +192.168.0.100 +>>> packet[2].src +192.168.0.100 +``` + +To test whether a layer is in a packet, you can use its name: + +```python +>>> 'IP' in packet +True +``` + +To see all possible field names, use the `packet.layer.field_names` attribute (i.e. `packet.ip.field_names`) or the autocomplete function on your interpreter. + +You can also get the original binary data of a field, or a pretty description of it: + +```python +>>> p.ip.addr.showname +Source or Destination Address: 10.0.0.10 (10.0.0.10) +# And some new attributes as well: +>>> p.ip.addr.int_value +167772170 +>>> p.ip.addr.binary_value +'\n\x00\x00\n' +``` + + +### Decrypting packet captures + +Pyshark supports automatic decryption of traces using the WEP, WPA-PWD, and WPA-PSK standards (WPA-PWD is the default). + +```python +>>> cap1 = pyshark.FileCapture('/tmp/capture1.cap', decryption_key='password') +>>> cap2 = pyshark.LiveCapture(interface='wi0', decryption_key='password', encryption_type='wpa-psk') +``` + +A tuple of supported encryption standards, SUPPORTED_ENCRYPTION_STANDARDS, +exists in each capture class. + +```python +>>> pyshark.FileCapture.SUPPORTED_ENCRYPTION_STANDARDS +('wep', 'wpa-pwd', 'wpa-psk') +>>> pyshark.LiveCapture.SUPPORTED_ENCRYPTION_STANDARDS +('wep', 'wpa-pwd', 'wpa-psk') +``` + +### Reading from a file using a display filter + +Pyshark display filters can be helpful in analyzing application focused traffic. +BPF filters do not offer as much flexibility as Wireshark's display filters. + +```python +>>> cap1 = pyshark.FileCapture('/tmp/capture1.cap', display_filter="dns") +>>> cap2 = pyshark.LiveCapture(interface='en0', display_filter="tcp.analysis.retransmission") +``` +## License +This project is licensed under MIT. Contributions to this project are accepted under the same license. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/src/pyshark/capture/capture.py new/pyshark-0.4.3/src/pyshark/capture/capture.py --- old/pyshark-0.4.2.11/src/pyshark/capture/capture.py 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/src/pyshark/capture/capture.py 2021-02-06 08:44:25.000000000 +0100 @@ -13,6 +13,11 @@ from pyshark.tshark.tshark_xml import packet_from_xml_packet, psml_structure_from_xml +if sys.version_info < (3, 8): + asyncTimeoutError = concurrent.futures.TimeoutError +else: + asyncTimeoutError = asyncio.exceptions.TimeoutError + class TSharkCrashException(Exception): pass @@ -62,6 +67,7 @@ self._log = logging.Logger(self.__class__.__name__, level=self.DEFAULT_LOG_LEVEL) self._closed = False self._custom_parameters = custom_parameters + self._eof_reached = False self.__tshark_version = None if include_raw and not use_json: @@ -128,9 +134,9 @@ raise StopCapture() try: - self.apply_on_packets(keep_packet, timeout=timeout) + self.apply_on_packets(keep_packet, timeout=timeout, packet_count=packet_count) self.loaded = True - except concurrent.futures.TimeoutError: + except asyncTimeoutError: pass def set_debug(self, set_to=True, log_level=logging.DEBUG): @@ -237,6 +243,7 @@ except EOFError: self._log.debug("EOF reached (sync)") + self._eof_reached = True break if packet: @@ -295,6 +302,7 @@ psml_structure=psml_struct) except EOFError: self._log.debug("EOF reached") + self._eof_reached = True break if packet: @@ -357,6 +365,7 @@ if not new_data: # Reached EOF + self._eof_reached = True raise EOFError() return None, existing_data @@ -410,7 +419,7 @@ try: process.kill() return await asyncio.wait_for(process.wait(), 1) - except concurrent.futures.TimeoutError: + except asyncTimeoutError: self._log.debug("Waiting for process to close failed, may have zombie process.") except ProcessLookupError: pass @@ -418,9 +427,10 @@ if os.name != "nt": raise elif process.returncode > 0: - raise TSharkCrashException("TShark seems to have crashed (retcode: %d). " - "Try rerunning in debug mode [ capture_obj.set_debug() ] or try updating tshark." - % process.returncode) + if process.returncode != 1 or self._eof_reached: + raise TSharkCrashException("TShark seems to have crashed (retcode: %d). " + "Try rerunning in debug mode [ capture_obj.set_debug() ] or try updating tshark." + % process.returncode) def close(self): self.eventloop.run_until_complete(self.close_async()) @@ -460,7 +470,7 @@ for key, val in self._custom_parameters.items(): params += [key, val] else: - raise Exception("Custom parameters type not supported.") + raise TypeError("Custom parameters type not supported.") if all(self.encryption): params += ["-o", "wlan.enable_decryption:TRUE", "-o", 'uat:80211_keys:"' + self.encryption[1] + '","' + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/src/pyshark/capture/inmem_capture.py new/pyshark-0.4.3/src/pyshark/capture/inmem_capture.py --- old/pyshark-0.4.2.11/src/pyshark/capture/inmem_capture.py 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/src/pyshark/capture/inmem_capture.py 2021-02-06 08:44:25.000000000 +0100 @@ -1,4 +1,6 @@ import asyncio +import datetime +import itertools import subprocess import os import struct @@ -85,52 +87,64 @@ else: return ("}%s%s" % (os.linesep, os.linesep)).encode(), ("}%s%s]" % (os.linesep, os.linesep)).encode(), 1 - def _write_packet(self, packet): + def _write_packet(self, packet, sniff_time): + if sniff_time is None: + now = time.time() + elif isinstance(sniff_time, datetime.datetime): + now = sniff_time.timestamp() + else: + now = float(sniff_time) + secs = int(now) + usecs = int((now * 1000000) % 1000000) # Write packet header - self._current_tshark.stdin.write(struct.pack("IIII", int(time.time()), 0, len(packet), len(packet))) + self._current_tshark.stdin.write(struct.pack("IIII", secs, usecs, len(packet), len(packet))) self._current_tshark.stdin.write(packet) - def parse_packet(self, binary_packet): + def parse_packet(self, binary_packet, sniff_time=None, timeout=DEFAULT_TIMEOUT): """Parses a single binary packet and returns its parsed version. DOES NOT CLOSE tshark. It must be closed manually by calling close() when you're done working with it. Use parse_packets when parsing multiple packets for faster parsing """ - return self.parse_packets([binary_packet])[0] + if sniff_time is not None: + sniff_time = [sniff_time] + return self.parse_packets([binary_packet], sniff_time, timeout)[0] - def parse_packets(self, binary_packets): + def parse_packets(self, binary_packets, sniff_times=None, timeout=DEFAULT_TIMEOUT): """Parses binary packets and return a list of parsed packets. DOES NOT CLOSE tshark. It must be closed manually by calling close() when you're done working with it. """ - return asyncio.get_event_loop().run_until_complete(self.parse_packets_async(binary_packets)) + return asyncio.get_event_loop().run_until_complete(self.parse_packets_async(binary_packets, sniff_times, timeout)) - async def parse_packets_async(self, binary_packets): + async def parse_packets_async(self, binary_packets, sniff_times=None, timeout=DEFAULT_TIMEOUT): """A coroutine which parses binary packets and return a list of parsed packets. DOES NOT CLOSE tshark. It must be closed manually by calling close() when you're done working with it. """ parsed_packets = [] + if sniff_times is None: + sniff_times = [] if not self._current_tshark: await self._get_tshark_process() - for binary_packet in binary_packets: - self._write_packet(binary_packet) + for binary_packet, sniff_time in itertools.zip_longest(binary_packets, sniff_times): + self._write_packet(binary_packet, sniff_time) def callback(pkt): parsed_packets.append(pkt) if len(parsed_packets) == len(binary_packets): raise StopCapture() - await self._get_parsed_packet_from_tshark(callback) + await self._get_parsed_packet_from_tshark(callback, timeout) return parsed_packets - async def _get_parsed_packet_from_tshark(self, callback): + async def _get_parsed_packet_from_tshark(self, callback, timeout): await self._current_tshark.stdin.drain() try: - await asyncio.wait_for(self.packets_from_tshark(callback, close_tshark=False), DEFAULT_TIMEOUT) + await asyncio.wait_for(self.packets_from_tshark(callback, close_tshark=False), timeout) except asyncio.TimeoutError: await self.close_async() raise asyncio.TimeoutError("Timed out while waiting for tshark to parse packet. " @@ -141,7 +155,7 @@ self._current_tshark = None await super(InMemCapture, self).close_async() - def feed_packet(self, binary_packet, linktype=LinkTypes.ETHERNET): + def feed_packet(self, binary_packet, linktype=LinkTypes.ETHERNET, timeout=DEFAULT_TIMEOUT): """ DEPRECATED. Use parse_packet instead. This function adds the packet to the packets list, and also closes and reopens tshark for @@ -158,12 +172,12 @@ """ warnings.warn("Deprecated method. Use InMemCapture.parse_packet() instead.") self._current_linktype = linktype - pkt = self.parse_packet(binary_packet) + pkt = self.parse_packet(binary_packet, timeout=timeout) self.close() self._packets.append(pkt) return pkt - def feed_packets(self, binary_packets, linktype=LinkTypes.ETHERNET): + def feed_packets(self, binary_packets, linktype=LinkTypes.ETHERNET, timeout=DEFAULT_TIMEOUT): """Gets a list of binary packets, parses them using tshark and returns their parsed values. Keeps the packets in the internal packet list as well. @@ -172,7 +186,7 @@ can be found in the class LinkTypes) """ self._current_linktype = linktype - parsed_packets = self.parse_packets(binary_packets) + parsed_packets = self.parse_packets(binary_packets, timeout=timeout) self._packets.extend(parsed_packets) self.close() return parsed_packets diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/src/pyshark/capture/pipe_capture.py new/pyshark-0.4.3/src/pyshark/capture/pipe_capture.py --- old/pyshark-0.4.2.11/src/pyshark/capture/pipe_capture.py 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/src/pyshark/capture/pipe_capture.py 2021-02-06 08:44:25.000000000 +0100 @@ -1,5 +1,5 @@ from pyshark.capture.capture import Capture - +import os class PipeCapture(Capture): def __init__(self, pipe, display_filter=None, only_summaries=False, @@ -46,5 +46,5 @@ def close(self): # Close pipe - self._pipe.close() + os.close(self._pipe) super(PipeCapture, self).close() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/src/pyshark/packet/layer.py new/pyshark-0.4.3/src/pyshark/packet/layer.py --- old/pyshark-0.4.2.11/src/pyshark/packet/layer.py 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/src/pyshark/packet/layer.py 2021-02-06 08:44:25.000000000 +0100 @@ -272,7 +272,7 @@ """ if self._showname_fields_converted_to_regular: return - for field_name in self._all_fields: + for field_name in list(self._all_fields): if ":" in field_name: field_value = self._all_fields.pop(field_name) if isinstance(field_value, dict): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/src/pyshark/tshark/tshark.py new/pyshark-0.4.3/src/pyshark/tshark/tshark.py --- old/pyshark-0.4.2.11/src/pyshark/tshark/tshark.py 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/src/pyshark/tshark/tshark.py 2021-02-06 08:44:25.000000000 +0100 @@ -101,4 +101,4 @@ with open(os.devnull, "w") as null: tshark_interfaces = subprocess.check_output(parameters, stderr=null).decode("utf-8") - return [line.split(".")[0] for line in tshark_interfaces.splitlines()] + return [line.split(" ")[1] for line in tshark_interfaces.splitlines() if not '\\\\.\\' in line] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/src/pyshark/tshark/tshark_json.py new/pyshark-0.4.3/src/pyshark/tshark/tshark_json.py --- old/pyshark-0.4.2.11/src/pyshark/tshark/tshark_json.py 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/src/pyshark/tshark/tshark_json.py 2021-02-06 08:44:25.000000000 +0100 @@ -55,5 +55,5 @@ return Packet(layers=layers, frame_info=JsonLayer('frame', frame_dict), number=int(frame_dict.get('frame.number', 0)), length=int(frame_dict['frame.len']), - sniff_time=frame_dict['frame.time'], + sniff_time=frame_dict['frame.time_epoch'], interface_captured=frame_dict.get('frame.interface_id')) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/src/pyshark/tshark/tshark_xml.py new/pyshark-0.4.3/src/pyshark/tshark/tshark_xml.py --- old/pyshark-0.4.2.11/src/pyshark/tshark/tshark_xml.py 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/src/pyshark/tshark/tshark_xml.py 2021-02-06 08:44:25.000000000 +0100 @@ -22,7 +22,7 @@ :return: Packet object. """ if not isinstance(xml_pkt, lxml.objectify.ObjectifiedElement): - parser = lxml.objectify.makeparser(huge_tree=True) + parser = lxml.objectify.makeparser(huge_tree=True, recover=True) xml_pkt = lxml.objectify.fromstring(xml_pkt, parser) if psml_structure: return _packet_from_psml_packet(xml_pkt, psml_structure) @@ -39,4 +39,4 @@ return Packet(layers=layers, frame_info=frame, number=geninfo.get_field_value('num'), length=geninfo.get_field_value('len'), sniff_time=geninfo.get_field_value('timestamp', raw=True), captured_length=geninfo.get_field_value('caplen'), - interface_captured=frame.get_field_value('interface_id', raw=True)) \ No newline at end of file + interface_captured=frame.get_field_value('interface_id', raw=True)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/src/setup.py new/pyshark-0.4.3/src/setup.py --- old/pyshark-0.4.2.11/src/setup.py 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/src/setup.py 2021-02-06 08:44:25.000000000 +0100 @@ -6,7 +6,7 @@ setup( name="pyshark", - version="0.4.2.11", + version="0.4.3", packages=find_packages(), package_data={'': ['*.ini', '*.pcapng']}, install_requires=['lxml', 'py'], @@ -22,5 +22,6 @@ 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', ], ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pyshark-0.4.2.11/tests/test_tshark.py new/pyshark-0.4.3/tests/test_tshark.py --- old/pyshark-0.4.2.11/tests/test_tshark.py 2019-09-25 08:56:50.000000000 +0200 +++ new/pyshark-0.4.3/tests/test_tshark.py 2021-02-06 08:44:25.000000000 +0100 @@ -48,6 +48,6 @@ b'1. wlan0\n2. any\n3. lo (Loopback)\n4. eth0\n5. docker0\n' ) actual = get_tshark_interfaces() - expected = ['1', '2', '3', '4', '5'] + expected = ['wlan0', 'any', 'lo', 'eth0', 'docker0'] assert actual == expected