def _AuthenticateRalinkLegacy(self, network): """ Authenticate with the specified wireless network. This function handles Ralink legacy cards that cannot use wpa_supplicant. Keyword arguments: network -- dictionary containing network info """ if network.get('key') != None: lines = self._GetRalinkInfo() for x in lines: info = x.split() if len(info) < 5: break if info[2] == network.get('essid'): if info[5] == 'WEP' or (info[5] == 'OPEN' and \ info[4] == 'WEP'): print 'Setting up WEP' cmd = ''.join([ 'iwconfig ', self.iface, ' key ', network.get('key') ]) if self.verbose: print cmd misc.Run(cmd) else: if info[5] == 'SHARED' and info[4] == 'WEP': print 'Setting up WEP' auth_mode = 'SHARED' key_name = 'Key1' elif info[5] == 'WPA-PSK': print 'Setting up WPA-PSK' auth_mode = 'WPAPSK' key_name = 'WPAPSK' elif info[5] == 'WPA2-PSK': print 'Setting up WPA2-PSK' auth_mode = 'WPA2PSK' key_name = 'WPAPSK' else: print 'Unknown AuthMode, can\'t complete ' + \ 'connection process!' return cmd_list = [] cmd_list.append('NetworkType=' + info[6]) cmd_list.append('AuthMode=' + auth_mode) cmd_list.append('EncrypType=' + info[4]) cmd_list.append('SSID=' + info[2]) cmd_list.append(key_name + '=' + network.get('key')) if info[5] == 'SHARED' and info[4] == 'WEP': cmd_list.append('DefaultKeyID=1') cmd_list.append('SSID=' + info[2]) for cmd in cmd_list: cmd = 'iwpriv ' + self.iface + ' ' if self.verbose: print cmd misc.Run(cmd)
def GetRfKillStatus(self): """ Determines if rfkill switch is active or not. Returns: True if rfkill (soft-)switch is enabled. """ cmd = 'rfkill list' rfkill_out = misc.Run(cmd) soft_blocks = filter(lambda x: x.startswith('Soft'), rfkill_out.split('\t')) for line in map(lambda x: x.strip(), soft_blocks): if line.endswith('yes'): return True return False
def GetRfKillStatus(self): """Determines if rfkill switch is active or not. Returns: True if rfkill (soft-)switch is enabled. """ cmd = 'rfkill list' rfkill_out = misc.Run(cmd) soft_blocks = [x for x in rfkill_out.split('\t') if x.startswith('Soft')] for line in [x.strip() for x in soft_blocks]: if line.endswith('yes'): return True return False
def SwitchRfKill(self): """ Switches the rfkill on/off for wireless cards. """ types = ['wifi', 'wlan', 'wimax', 'wwan'] try: if self.GetRfKillStatus(): action = 'unblock' else: action = 'block' for t in types: cmd = ['rfkill', action, t] print("rfkill: %sing %s" % (action, t)) misc.Run(cmd) return True except Exception as e: raise e
def test_misc_run(self): output = misc.Run(['echo', 'hi']).strip() self.assertEqual('hi', output)