Exemplo n.º 1
0
def smart_scan():
    #First, getting all available interfaces
    networks = []
    interface_data = get_ip_addr()
    for interface_name in interface_data.keys():
        #Autofiltering unsuitable interfaces
        interface_info = interface_data[interface_name]
        state = interface_info["state"]
        ip = interface_info["addr"] if interface_info["addr"] else None
        if state == "up" and ip is not None:
            #Only using interface if it's up and has an IP
            #Automatically filters out localhost
            networks.append(["{}:{}".format(interface_name, ip), ip])
    if not networks:
        #No suitable interfaces found after filtering
        Printer(ffs("No suitable network interfaces found!", o.cols), i, o, 3)
        return None
    if len(networks) == 1:
        #Only one good interface, using it automatically
        network_ip = networks[0][1]
    else:
        #Allowing user to pick an interface
        network_ip = Listbox(networks, i, o).activate()
        if network_ip is None:  #Listbox exited without making a choice
            return None
    network_ip = get_network_from_ip(network_ip)
    chosen_ports = Checkbox(heuristic_ports,
                            i,
                            o,
                            name="NMap: select port types",
                            final_button_name="Run scan").activate()
    if chosen_ports is None: return None
    chosen_port_list = [
        port_choice for port_choice in chosen_ports
        if chosen_ports[port_choice] == True
    ]
    port_string = ",".join(chosen_port_list)
    #So the library I'm using is silently failing. I launch the scan from command-line and see:
    #
    #WARNING: Duplicate port number(s) specified.  Are you alert enough to be using Nmap?  Have some coffee or Jolt(tm).
    #
    #Well, thank you, but it's a script and f**k off.
    port_string = ",".join(list(set(port_string.split(","))))
    #De-duplicated and ready to go.
    print(port_string)
    Printer(ffs("Scanning {}".format(network_ip), o.cols), i, o, 0)
    nm = nmap.PortScanner()
    nm.scan(network_ip, arguments="-n -p {}".format(port_string))
    print(nm)
    show_quick_scan_results_for_network(network_ip, nm)
Exemplo n.º 2
0
def scan_network_menu():
    #A report to be passed to Menu object
    networks = []
    #External library function that parses "ip addr" output
    interface_data = get_ip_addr()
    for interface_name in interface_data.keys():
        interface_info = interface_data[interface_name]
        state = interface_info["state"]
        ip = interface_info["addr"] if interface_info["addr"] else "None"
        networks.append([
            "{}:{}, {}".format(interface_name, state, ip),
            lambda x=ip: quick_scan_network_by_ip(x)
        ])
    Menu(networks, i, o).activate()