Skip to content

Commit

Permalink
Changed the selection of the interface in the capture
Browse files Browse the repository at this point in the history
  • Loading branch information
shramos committed Oct 9, 2020
1 parent ad053e2 commit 9aa31fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 5 additions & 1 deletion polymorph/UI/maininterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def no_captured():
cap = capture(userfilter=args["-f"],
count=args["-c"],
time=args["-t"],
func=func)
func=func,
iface=args["-i"])
if cap:
run_tlistinterface(cap, args["-f"])
else:
Expand All @@ -150,6 +151,8 @@ def _capture_opts():
"default": False},
"-vv": {"type": bool,
"default": False},
"-i": {"type": str,
"default": None},
"-c": {"type": int,
"default": 0},
"-t": {"type": int,
Expand All @@ -166,6 +169,7 @@ def capture_help():
options = OrderedDict([
("-h", "prints the help."),
("-f", "allows packet filtering using the BPF notation."),
("-i", "interface for capturing network packets."),
("-c", "number of packets to capture."),
("-t", "stop sniffing after a given time."),
("-file", "read a .pcap file from disk."),
Expand Down
13 changes: 5 additions & 8 deletions polymorph/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
POLYM_PATH = dirname(polymorph.__file__)


def capture(userfilter=None, pcapname=".tmp.pcap", func=None, count=0, time=None):
def capture(userfilter=None, pcapname=".tmp.pcap", func=None, count=0, time=None, iface=None):
"""This function is a wrapper function above the sniff scapy function. The
result is a list of templates.
Expand All @@ -35,22 +35,19 @@ def capture(userfilter=None, pcapname=".tmp.pcap", func=None, count=0, time=None
Number of packets to capture.
time : int
Stop sniffing after a given time.
iface : :obj:`str`
Interface for capturing network packets
Returns
-------
:obj:`TList`
List of templates
"""
# We manually obtain the available network interfaces
if platform.system() == "Linux":
interfaces = os.listdir('/sys/class/net/')
else:
interfaces = None
if func:
plist = sniff(prn=func, count=count, timeout=time, iface=interfaces)
plist = sniff(prn=func, count=count, timeout=time, iface=iface)
else:
plist = sniff(count=count, timeout=time, iface=interfaces)
plist = sniff(count=count, timeout=time, iface=iface)
# Save the list of packets to disk for later reading with Pyshark
if len(plist) > 0:
pcap_path = join(POLYM_PATH, pcapname)
Expand Down

0 comments on commit 9aa31fe

Please sign in to comment.