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

Add fifo option to FileCapture #621

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pyshark/capture/file_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def __init__(self, input_file=None, keep_packets=True, display_filter=None, only
self.input_filepath = pathlib.Path(input_file)
if not self.input_filepath.exists():
raise FileNotFoundError(f"[Errno 2] No such file or directory: {self.input_filepath}")
if not self.input_filepath.is_file():
raise FileNotFoundError(f"{self.input_filepath} is a directory")
if not self.input_filepath.is_file() and not self.input_filepath.is_fifo():
raise FileNotFoundError(f"{self.input_filepath} is not a file or fifo")

self.keep_packets = keep_packets
self._packet_generator = self._packets_from_tshark_sync()
Expand Down
10 changes: 7 additions & 3 deletions src/pyshark/capture/live_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ def __init__(self, interface=None, bpf_filter=None, display_filter=None, only_su

def get_parameters(self, packet_count=None):
"""Returns the special tshark parameters to be used according to the configuration of this class."""
params = super(LiveCapture, self).get_parameters(packet_count=packet_count)
# Read from STDIN
params += ["-i", "-"]
params = super(LiveCapture, self).get_parameters(
packet_count=packet_count)
# Read directly from interfaces
for interface in self.interfaces:
Copy link
Owner

Choose a reason for hiding this comment

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

This isn't related to this PR, and there's a reason we use dumpcap and don't read directly from the interface

params += ["-i", interface]
return params

def _verify_capture_parameters(self):
all_interfaces_names = tshark.get_all_tshark_interfaces_names(self.tshark_path)
all_interfaces_lowercase = [interface.lower() for interface in all_interfaces_names]
for each_interface in self.interfaces:
if each_interface.startswith("rpcap://"):
continue
if each_interface.isnumeric():
continue
if each_interface.lower() not in all_interfaces_lowercase:
Expand Down
2 changes: 1 addition & 1 deletion src/pyshark/packet/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __getattr__(self, item):
Allows layers to be retrieved via get attr. For instance: pkt.ip
"""
for layer in self.layers:
if layer.layer_name == item:
if layer.layer_name.lower() == item:
Copy link

Choose a reason for hiding this comment

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

Change to:
if layer.layer_name.lower() == item.lower():

return layer
raise AttributeError("No attribute named %s" % item)

Expand Down