Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature pipe captures #280

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
8 changes: 5 additions & 3 deletions src/pyshark/capture/pipe_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self, pipe, display_filter=None, only_summaries=False,
decryption_key=None, encryption_type='wpa-pwk', decode_as=None,
disable_protocol=None, tshark_path=None, override_prefs=None, use_json=False, include_raw=False):
"""
Receives a file-like and reads the packets from there (pcap format).
Receives a string for the filename and reads the packets from there (pcap format). Does not close the pipe.

:param bpf_filter: BPF filter to use on packets.
:param display_filter: Display (wireshark) filter to use.
Expand Down Expand Up @@ -40,8 +40,10 @@ def get_parameters(self, packet_count=None):
return params[:-1]

def close(self):
# Close pipe
# self._pipe.close() # Don't close the pipe. This should be the job of whatever is piping into it.
"""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually just remove this entire method now, the docs in the classdoc should suffice

Closes the capture, but not the pipe.
"""
# Close the capture.
super(PipeCapture, self).close()

# Backwards compatibility
Expand Down
8 changes: 4 additions & 4 deletions src/pyshark/capture/pipe_ring_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class PipeRingCapture(PipeCapture):
"""

def __init__(self, pipe, ring_file_size=1024, num_ring_files=2, ring_file_name=None,
display_filter=None, only_summaries=False, decryption_key=None,
only_summaries=False, decryption_key=None,
encryption_type='wpa-pwk', decode_as=None, disable_protocol=None,
tshark_path=None, override_prefs=None, include_raw=False, use_json=False):
tshark_path=None, override_prefs=None, include_raw=False, use_json=False, **kwargs):
"""
Creates a new live capturer on a given interface. Does not start the actual capture itself.
:param ring_file_size: Size of the ring file in kB, default is 1024
Expand All @@ -38,10 +38,10 @@ def __init__(self, pipe, ring_file_size=1024, num_ring_files=2, ring_file_name=N
:param override_prefs: A dictionary of tshark preferences to override, {PREFERENCE_NAME: PREFERENCE_VALUE, ...}.
:param disable_protocol: Tells tshark to remove a dissector for a specifc protocol.
"""
if display_filter is not None:
if "display_filter" in kwargs.keys():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this as well as the exception. I don't think it's needed. Again, just write in the doc that display filters are not supported.

If you feel strongly about having this exception, then it's better the previous way. This is bad because it "swallows" any kwargs the user may have inputted (say they misspelt use_json, it'll suddenly not fail but not work either)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree, I should pass them up to the super, I think it's important to do a hard exception for this since every other capture allows it.

raise DisplayFilterNotAllowedException("Display Filters are not allowed in PipeRingCapture.")

super(PipeRingCapture, self).__init__(pipe, display_filter=display_filter, only_summaries=only_summaries,
super(PipeRingCapture, self).__init__(pipe, display_filter=None, only_summaries=only_summaries,
decryption_key=decryption_key, encryption_type=encryption_type,
tshark_path=tshark_path, decode_as=decode_as, disable_protocol=disable_protocol,
override_prefs=override_prefs, include_raw=include_raw, use_json=use_json)
Expand Down