def connect_wifi(): interface = selectWirelessInterface() if interface is None: print "There is no wireless interface available" return params = {} params['interface'] = interface wifiNetworks = [] wifiNetworkStrings = [] response = guh.send_command("NetworkManager.GetWirelessAccessPoints", params) wifiNetworks = response['params']['wirelessAccessPoints'] for accessPoint in wifiNetworks: wifiNetworkStrings.append( ("%10s | %s%s | %s %s | %s" % (accessPoint['ssid'], accessPoint['signalStrength'], '%', accessPoint['frequency'], '[GHz]', accessPoint['macAddress']))) selection = selector.get_selection("Wifi access points", wifiNetworkStrings) if not selection: return None params['ssid'] = wifiNetworks[selection]['ssid'] if wifiNetworks[selection]['protected'] == True: params['password'] = raw_input( "Please enter the password for wifi network %s: " % (params['ssid'])) response = guh.send_command("NetworkManager.ConnectWifiNetwork", params) guh.print_networkmanager_error_code( response['params']['networkManagerError'])
def show_network_status(): params = {} response = guh.send_command("NetworkManager.GetNetworkStatus", params) if 'status' in response['params']: guh.print_json_format(response['params']['status']) else: guh.print_networkmanager_error_code( response['params']['networkManagerError'])
def disconnect_networkdevice(): interface = selectWirelessInterface() if interface is None: print "There is no wireless interface available" return params = {} params['interface'] = interface response = guh.send_command("NetworkManager.DisconnectInterface", params) guh.print_networkmanager_error_code( response['params']['networkManagerError'])
def scan_wirelessaccesspoints(): interface = selectWirelessInterface() if interface is None: print "There is no wireless interface available" return params = {} params['interface'] = interface response = guh.send_command("NetworkManager.ScanWifiNetworks", params) guh.print_networkmanager_error_code( response['params']['networkManagerError'])
def enable_networking(): params = {} options = ["enable", "disable"] selection = guh.get_selection("Do you want to do with the networking: ", options) if selection == 0: params['enable'] = True else: params['enable'] = False response = guh.send_command("NetworkManager.EnableNetworking", params) guh.print_networkmanager_error_code( response['params']['networkManagerError'])
def selectWirelessInterface(): params = {} response = guh.send_command("NetworkManager.GetNetworkDevices", params) if response['params'][ 'networkManagerError'] != 'NetworkManagerErrorNoError': print("There is no wireless interface available") guh.print_networkmanager_error_code( response['params']['networkManagerError']) return None if len(response['params']['wirelessNetworkDevices']) is 1: return response['params']['wirelessNetworkDevices'][0]['interface'] else: interfaces = [] for wirelessNetworkDevice in response['params'][ 'wirelessNetworkDevices']: interfaces.append(wirelessNetworkDevice['interface']) selection = guh.get_selection("Please select a wifi interface:", interfaces) return interfaces[selection]
def list_wirelessaccesspoints(): interface = selectWirelessInterface() if interface is None: return params = {} params['interface'] = interface response = guh.send_command("NetworkManager.GetWirelessAccessPoints", params) if response['params'][ 'networkManagerError'] != 'NetworkManagerErrorNoError': guh.print_networkmanager_error_code( response['params']['networkManagerError']) else: print("Wireless accesspoints for interface %s" % interface) print( "---------------------------------------------------------------------" ) for accessPoint in response['params']['wirelessAccessPoints']: print("%20s | %5s%s | %6s %6s | %s | %s" % (accessPoint['ssid'], accessPoint['signalStrength'], '%', accessPoint['frequency'], '[GHz]', accessPoint['macAddress'], accessPoint['protected']))