Esempio n. 1
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. 2
0
def wireless_status():
    w_status = wpa_cli.connection_status()
    state = w_status['wpa_state']
    status_menu_contents = [[["state:", state]]] #State is an element that's always there, let's see possible states
    if state == 'COMPLETED':
        #We have bssid, ssid and key_mgmt at least
        status_menu_contents.append(['SSID: '+w_status['ssid']])
        status_menu_contents.append(['BSSID: '+w_status['bssid']])
        key_mgmt = w_status['key_mgmt']
        status_menu_contents.append([['Security:', key_mgmt]])
        #If we have WPA in key_mgmt, we also have pairwise_cipher and group_cipher set to something other than NONE so we can show them
        if key_mgmt != 'NONE':
            try: #What if?
                group = w_status['group_cipher']
                pairwise = w_status['pairwise_cipher']
                status_menu_contents.append([['Group/Pairwise:', group+"/"+pairwise]])
            except:
                pass
    elif state in ['AUTHENTICATING', 'SCANNING', 'ASSOCIATING']:
        pass #These states don't have much information
    #In any case, we might or might not have IP address info
    status_menu_contents.append([['IP address:',w_status['ip_address'] if 'ip_address' in w_status else 'None']])
    #We also always have WiFi MAC address as 'address'
    status_menu_contents.append(['MAC: '+w_status['address']])
    status_menu = Menu(status_menu_contents, i, o, "Wireless status menu", entry_height=2)
    status_menu.activate()
Esempio n. 3
0
def status_refresher_data():
    try:
        w_status = wpa_cli.connection_status()
    except:
        return ["wpa_cli fail".center(o.cols)]
    #Getting data
    state = w_status['wpa_state']
    ip = w_status['ip_address'] if 'ip_address' in w_status else 'None'
    ap = w_status['ssid'] if 'ssid' in w_status else 'None'

    #Formatting strings for screen width
    if len(ap) > o.cols:  #AP doesn't fit on the screen
        ap = ellipsize(ap, o.cols)
    if o.cols >= len(ap) + len("SSID: "):
        ap = "SSID: " + ap
    ip_max_len = 15  #3x4 digits + 3 dots
    if o.cols >= ip_max_len + 4:  #disambiguation fits on the screen
        ip = "IP: " + ip
    data = [ap.center(o.cols), ip.center(o.cols)]

    #Formatting strings for screen height
    #Additional state info
    if o.rows > 2:
        data.append(("St: " + state).center(o.cols))
    #Button usage tips - we could have 3 rows by now, can we add at least two more?
    if o.rows >= 5:
        empty_rows = o.rows - 5  #ip, ap, state and two rows we'll add
        for i in range(empty_rows):
            data.append("")  #Padding
        data.append("ENTER: more info".center(o.cols))
        data.append("RIGHT: rescan".center(o.cols))

    return data
Esempio n. 4
0
def wireless_status():
    w_status = wpa_cli.connection_status()
    state = w_status['wpa_state']
    status_menu_contents = [[["state:", state]]] #State is an element that's always there, let's see possible states
    if state == 'COMPLETED':
        #We have bssid, ssid and key_mgmt at least
        status_menu_contents.append(['SSID: '+w_status['ssid']])
        status_menu_contents.append(['BSSID: '+w_status['bssid']])
        key_mgmt = w_status['key_mgmt']
        status_menu_contents.append([['Security:', key_mgmt]])
        #If we have WPA in key_mgmt, we also have pairwise_cipher and group_cipher set to something other than NONE so we can show them
        if key_mgmt != 'NONE':
            try: #What if?
                group = w_status['group_cipher']
                pairwise = w_status['pairwise_cipher']
                status_menu_contents.append([['Group/Pairwise:', group+"/"+pairwise]])
            except:
                pass
    elif state in ['AUTHENTICATING', 'SCANNING', 'ASSOCIATING']:
        pass #These states don't have much information
    #In any case, we might or might not have IP address info
    status_menu_contents.append([['IP address:',w_status['ip_address'] if 'ip_address' in w_status else 'None']])
    #We also always have WiFi MAC address as 'address'
    status_menu_contents.append(['MAC: '+w_status['address']])
    status_menu = Menu(status_menu_contents, i, o, "Wireless status menu", entry_height=2)
    status_menu.activate()
Esempio n. 5
0
def status_refresher_data():
    try:
        w_status = wpa_cli.connection_status()
    except:
        return ["wpa_cli fail"]
    state = w_status['wpa_state']
    ip = w_status['ip_address'] if 'ip_address' in w_status else 'None'
    ap = w_status['ssid'] if 'ssid' in w_status else 'None'
    return [ap.rjust(o.cols), ip.rjust(o.cols)]    
Esempio n. 6
0
def status_refresher_data():
    try:
        w_status = wpa_cli.connection_status()
    except:
        return ["wpa_cli fail"]
    state = w_status['wpa_state']
    ip = w_status['ip_address'] if 'ip_address' in w_status else 'None'
    ap = w_status['ssid'] if 'ssid' in w_status else 'None'
    return [ap.rjust(o.cols), ip.rjust(o.cols)]
Esempio n. 7
0
def reconnect():
    try:
        w_status = wpa_cli.connection_status()
    except:
        return ["wpa_cli fail".center(o.cols)]
    ip = w_status.get('ip_address', None)
    ap = w_status.get('ssid', None)
    if not ap:
        Printer("Not connected!", i, o, 1)
        return False
    id = w_status.get('id', None)
    if not id:
        logger.error(
            "Current network {} is not in configured network list!".format(ap))
        return False
    disable_network(id)
    scan()
    enable_network(id)
    return True