Esempio n. 1
0
def connect_to_network(network_info):
    #First, looking in the known networks
    configured_networks = wpa_cli.list_configured_networks()
    for network in configured_networks:
        if network_info['ssid'] == network['ssid']:
            Printer([network_info['ssid'], "known,connecting"], i, o, 1)
            wpa_cli.enable_network(network['network id'])
            wpa_cli.save_config()
            raise MenuExitException
    #Then, if it's an open network, just connecting
    if wpa_cli.is_open_network(network_info):
        network_id = wpa_cli.add_network()
        Printer(["Network is open", "adding to known"], i, o, 1)
        ssid = network_info['ssid']
        wpa_cli.set_network(network_id, 'ssid', '"{}"'.format(ssid))
        wpa_cli.set_network(network_id, 'key_mgmt', 'NONE')
        Printer(["Connecting to", network_info['ssid']], i, o, 1)
        wpa_cli.enable_network(network_id)
        wpa_cli.save_config()
        raise MenuExitException
    #Offering to enter a password
    else:
        input = CharArrowKeysInput(i, o, message="Password:"******"WiFi password enter UI element")
        password = input.activate()
        if password is None:
            return False
        network_id = wpa_cli.add_network()
        Printer(["Password entered", "adding to known"], i, o, 1)
        ssid = network_info['ssid']
        wpa_cli.set_network(network_id, 'ssid', '"{}"'.format(ssid))
        wpa_cli.set_network(network_id, 'psk', '"{}"'.format(password))
        Printer(["Connecting to", network_info['ssid']], i, o, 1)
        wpa_cli.enable_network(network_id)
        wpa_cli.save_config()
        raise MenuExitException
Esempio n. 2
0
 def check_connect_wifi(self):
     if self.badnet is not None:
         self.badnets.append(self.badnet)
         self.badnet = None
     status = wpa_cli.connection_status()
     state = status["wpa_state"]
     if state == "COMPLETED":
         return status
     else:
         print("Not connected, retrying!")
         wpa_cli.scan()
         sleep(5)
         avail_networks = wpa_cli.get_scan_results()
         for network in avail_networks:
             if network["bssid"] in self.badnets:
                 print("Avoiding bad network {}".format(network["bssid"]))
                 continue
             elif wpa_cli.is_open_network(network):
                 #Adding net network, gotta reset the smash counter
                 self.smash_counter = 0
                 id = wpa_cli.add_open_network(network)
                 wpa_cli.select_network(id)
                 print("Selected '{}'".format(network["ssid"]))
                 sleep(5)
                 print("Hope we got the IP now")
                 return
         return None
Esempio n. 3
0
def connect_to_network(network_info):
    #First, looking in the known networks
    configured_networks = wpa_cli.list_configured_networks()
    for network in configured_networks:
        if network_info['ssid'] == network['ssid']:
            Printer([network_info['ssid'], "known,connecting"], i, o, 1)
            wpa_cli.enable_network(network['network id'])
            wpa_cli.save_config()
            raise MenuExitException
    #Then, if it's an open network, just connecting
    if wpa_cli.is_open_network(network_info):
        network_id = wpa_cli.add_network()
        Printer(["Network is open", "adding to known"], i, o, 1)
        ssid = network_info['ssid']
        wpa_cli.set_network(network_id, 'ssid', '"{}"'.format(ssid))
        wpa_cli.set_network(network_id, 'key_mgmt', 'NONE')
        Printer(["Connecting to", network_info['ssid']], i, o, 1)
        wpa_cli.enable_network(network_id)
        wpa_cli.save_config()
        raise MenuExitException
    #Offering to enter a password
    else:
        input = NumpadCharInput(i, o, message="Password:"******"WiFi password enter UI element")
        password = input.activate()
        if password is None:
            return False
        network_id = wpa_cli.add_network()
        Printer(["Password entered", "adding to known"], i, o, 1)
        ssid = network_info['ssid']
        wpa_cli.set_network(network_id, 'ssid', '"{}"'.format(ssid))
        wpa_cli.set_network(network_id, 'psk', '"{}"'.format(password))
        Printer(["Connecting to", network_info['ssid']], i, o, 1)
        wpa_cli.enable_network(network_id)
        wpa_cli.save_config()
        raise MenuExitException
Esempio n. 4
0
def network_info_menu(network_info):
    network_info_contents = [
    ["Connect", lambda x=network_info: connect_to_network(x)],
    ["BSSID", lambda x=network_info['bssid']: Printer(x, i, o, 5, skippable=True)],
    ["Frequency", lambda x=network_info['frequency']: Printer(x, i, o, 5, skippable=True)],
    ["Open" if wpa_cli.is_open_network(network_info) else "Secured", lambda x=network_info['flags']: Printer(x, i, o, 5, skippable=True)]]
    network_info_menu = Menu(network_info_contents, i, o, "Wireless network info", catch_exit=False)
    network_info_menu.activate()
Esempio n. 5
0
def network_info_menu(network_info):
    network_info_contents = [
    ["Connect", lambda x=network_info: connect_to_network(x)],
    ["BSSID", lambda x=network_info['bssid']: Printer(x, i, o, 5, skippable=True)],
    ["Frequency", lambda x=network_info['frequency']: Printer(x, i, o, 5, skippable=True)],
    ["Open" if wpa_cli.is_open_network(network_info) else "Secured", lambda x=network_info['flags']: Printer(x, i, o, 5, skippable=True)]]
    network_info_menu = Menu(network_info_contents, i, o, "Wireless network info", catch_exit=False)
    network_info_menu.activate()
Esempio n. 6
0
def connect_to_network(network_info):
    #First, looking in the known networks
    configured_networks = wpa_cli.list_configured_networks()
    for network in configured_networks:
        if network_info['ssid'] == network['ssid']:
            Printer([network_info['ssid'], "known,connecting"], i, o, 1)
            wpa_cli.select_network(network['network id'])
            return True
    #Then, if it's an open network, just connecting
    if wpa_cli.is_open_network(network_info):
        network_id = wpa_cli.add_network()
        Printer(["Network is open", "adding to known"], i, o, 1)
        wpa_cli.set_network(network_id, 'ssid',
                            '"' + network_info['ssid'] + '"')
        wpa_cli.set_network(network_id, 'key_mgmt', 'NONE')
        Printer(["Connecting to", network_info['ssid']], i, o, 1)
        wpa_cli.select_network(network_id)
        return True
    #No passkey/WPS PIN input possible yet and I cannot yet test WPS button functionality.
    else:
        o.display_data("Network password", "unknown")
        sleep(1)
        return False