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

Netmon refactor fix #86

Open
wants to merge 2 commits into
base: sulley_refactor
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
41 changes: 33 additions & 8 deletions network_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,39 @@ def log_error(message=None):
sys.exit(1)


def create_usage():
def get_ifs():
"""
Get a list of network interfaces on the system.

:rtype : list[str]
:return: List of network interfaces.
"""
ifs = []
for index, pcapy_device in enumerate(pcapy.findalldevs()):
ifs.append(pcapy_device)
return ifs


def create_usage(ifs):
"""
Return usage string.

:type ifs: list[str]
:param ifs: List of network interfaces to include in help text.

:rtype : str
:return: Usage text.
"""
message = """USAGE: network_monitor.py
<-d|--device DEVICE #> device to sniff on (see list below)
[-f|--filter PCAP FILTER] BPF filter string
[-P|--log_path PATH] log directory to store pcaps to
[-l|--log_level LEVEL] log level (default 1), increase for more verbosity
[--port PORT] TCP port to bind this agent to

Network Device List:"""
for index, pcapy_device in enumerate(pcapy.findalldevs()):
IFS.append(device)
Network Device List:
"""
for index, pcapy_device in enumerate(ifs):
# if we are on windows, try and resolve the device UUID into an IP address.
if sys.platform.startswith("win"):
import _winreg
Expand Down Expand Up @@ -217,10 +239,10 @@ def set_log_path(self, new_log_path):
self.log_path = new_log_path


if __name__ == "__main__":
usage_message = create_usage()
def main():
ifs = get_ifs()
usage_message = create_usage(ifs)
rpc_port = 26001
IFS = []
opts = None

# parse command line options.
Expand All @@ -236,7 +258,7 @@ def set_log_path(self, new_log_path):

for opt, arg in opts:
if opt in ("-d", "--device"):
device = IFS[int(arg)]
device = ifs[int(arg)]
if opt in ("-f", "--filter"):
pcap_filter = arg
if opt in ("-P", "--log_path"):
Expand All @@ -254,3 +276,6 @@ def set_log_path(self, new_log_path):
servlet.serve_forever()
except:
pass

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
'utils': './utils',
'web': './web'
},
install_requires=['pydot2==1.0.33', 'tornado==4.0.2', 'Flask==0.10.1']
install_requires=['pydot2==1.0.33', 'tornado==4.0.2', 'Flask==0.10.1', 'pcapy', 'impacket']
)