diff --git a/network_monitor.py b/network_monitor.py index e803f87..4286ba8 100644 --- a/network_monitor.py +++ b/network_monitor.py @@ -19,7 +19,29 @@ 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 @@ -27,9 +49,9 @@ def create_usage(): [-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 @@ -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. @@ -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"): @@ -254,3 +276,6 @@ def set_log_path(self, new_log_path): servlet.serve_forever() except: pass + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/setup.py b/setup.py index 1161a97..b41003f 100644 --- a/setup.py +++ b/setup.py @@ -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'] ) \ No newline at end of file