def test_unencrypted(self): cell = Cell() cell.ssid = 'SSID' cell.encrypted = False scheme = Scheme.for_cell('wlan0', 'test', cell) self.assertEqual(scheme.options, { 'wireless-essid': 'SSID', 'wireless-channel': 'auto', })
def test_wpa(self): cell = Cell() cell.ssid = 'SSID' cell.encrypted = True cell.encryption_type = 'wpa' scheme = Scheme.for_cell('wlan0', 'test', cell, 'passkey') self.assertEqual(scheme.options, { 'wpa-ssid': 'SSID', 'wpa-psk': 'ea1548d4e8850c8d94c5ef9ed6fe483981b64c1436952cb1bf80c08a68cdc763', 'wireless-channel': 'auto', })
def test_wep_ascii(self): cell = Cell() cell.ssid = 'SSID' cell.encrypted = True cell.encryption_type = 'wep' # ascii key lengths: 5, 13, 16, 29 ascii_keys = ('a' * 5, 'a' * 13, 'a' * 16, 'a' * 29) for key in ascii_keys: scheme = Scheme.for_cell('wlan0', 'test', cell, key) self.assertEqual(scheme.options, { 'wireless-essid': 'SSID', 'wireless-key': 's:' + key })
def test_wep_hex(self): cell = Cell() cell.ssid = 'SSID' cell.encrypted = True cell.encryption_type = 'wep' # hex key lengths: 10, 26, 32, 58 hex_keys = ("01234567ab", "0123456789abc" * 2, "0123456789abcdef" * 2, "0123456789abc" * 2 + "0123456789abcdef" * 2) for key in hex_keys: scheme = Scheme.for_cell('wlan0', 'test', cell, key) self.assertEqual(scheme.options, { 'wireless-essid': 'SSID', 'wireless-key': key })
def find_cell(interface, query): cell = Cell.where(interface, lambda cell: cell.ssid.lower() == query.lower()) try: cell = cell[0] except IndexError: cell = fuzzy_find_cell(interface, query) return cell
def fuzzy_find_cell(interface, query): match_partial = lambda cell: fuzzy_match(query, cell.ssid) matches = Cell.where(interface, match_partial) num_unique_matches = len(set(cell.ssid for cell in matches)) assert num_unique_matches > 0, "Couldn't find a network that matches '{}'".format(query) assert num_unique_matches < 2, "Found more than one network that matches '{}'".format(query) # Several cells of the same SSID if len(matches) > 1: matches.sort(key=lambda cell: cell.signal) return matches[0]
def autoconnect_command(args): ssids = [cell.ssid for cell in Cell.all(args.interface)] for scheme in Scheme.all(): # TODO: make it easier to get the SSID off of a scheme. ssid = scheme.options.get('wpa-ssid', scheme.options.get('wireless-essid')) if ssid in ssids: sys.stderr.write('Connecting to "%s".\n' % ssid) try: scheme.activate() except ConnectionError: assert False, "Failed to connect to %s." % scheme.name break else: assert False, "Couldn't find any schemes that are currently available."
def scan_command(args): print_table([[cell.signal, cell.ssid, 'protected' if cell.encrypted else 'unprotected'] for cell in Cell.all(args.interface)])