def connect_wifi(self, ssid, password): if ssid is not None: try: self.status_updated.emit("Verbinde..") cell = Cell.where("wlan0", lambda w: w.ssid == f"{ssid}")[0] if cell.encrypted is True and not password: self.status_updated.emit("Passwort inkorrekt") return scheme = SchemeWPA('wlan0', ssid, { "ssid": ssid, "psk": password }) if scheme.iface in [iface.iface for iface in SchemeWPA.all()]: scheme.delete() scheme.save() scheme.activate() self.status_updated.emit(self.get_status()) self.ip_updated.emit(self.get_ip()) except IndexError: self.status_updated.emit("Netzwerk nicht gefunden") except: self.status_updated.emit("Fehler bei der Verbindungsaufnahme") e = sys.exc_info()[0] pass finally: self.finished.emit()
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 unique_wifi_scan (WFinterface, WFaddr): # for cell in Cell.all(WFinterface): # if cell.address == WFaddr: # return cell.ssid # return False cell = Cell.where(WFinterface, lambda cell: cell.address.lower() == WFaddr.lower()) for c in cell: return c.signal return False
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 _cell_find(iface, ssid): """ look up cell by network interface and ssid :param iface: network interface :param ssid: network name :return: the first cell that matches the arguments """ cells = Cell.where(iface, lambda c: c.ssid.lower() == ssid.lower()) # if the cell doesn't exist, cell[0] will raise an IndexError cell = cells[0] return cell
def run_scan(self): scan = Cell.where(interface, filter) if(len(scan) > 0): network = scan[0] if(network.encrypted): if(network.encryption_type is 'wep'): return (10, "WEP Network Detected - Passwords can easily be hacked.") if(network.encryption_type is 'wpa'): return (20, "WPA Network Detected - Passwords may be vulnerable.") if(network.encryption_type is 'wpa2'): return (100, "Network encryption appears secure") else: return (100, "Network encryption apperas secure") else: return (0, "No network encryption")
def connect(esid, passkey=None, intf='wlan0'): cells = Cell.where(intf, lambda c: c.ssid == esid); if len(cells) == 0: raise LookupError('Network was not found'); if len(cells) > 1: raise LookupError('Sorry, network SSID is ambiguous'); scheme = Scheme.for_cell(intf, STORED_SCHEME_NAME, cells[0], passkey); old = Scheme.find(intf, STORED_SCHEME_NAME); if old is not None: old.delete(); scheme.save(); scheme.activate();
def connect(adapter, ssid, psk=None, quiet=False): if not quiet: print "***setting up wireless adapter***" signal = [] # get a list of all the available SSIDs that match the arg ssid cells = Cell.where(adapter, lambda x: x.ssid == ssid) print cells if len(cells) == 0: if not quiet: print "Cannot find SSID:", ssid return False # find the SSID with the best signal strength and select it as the cell to connect to for c in cells: signal.append(c.signal) max_signal = max(signal) max_index = signal.index(max_signal) cell = cells[max_index] scheme = Scheme.for_cell(adapter, ssid, cell, passkey=psk) # overwrite the scheme if already in '/etc/network/interfaces' # save it to '/etc/network/interfaces' if not if Scheme.find(adapter, ssid): scheme.delete() scheme.save() else: scheme.save() # attempt to connect to ssid try: if not quiet: print 'connecting to SSID:', cell.ssid scheme.activate() if not quiet: print 'connection successful' return True except: if not quiet: print('connection failed') return False
def run_scan(self): scan = Cell.where(interface, filter) if (len(scan) > 0): network = scan[0] if (network.encrypted): if (network.encryption_type is 'wep'): return ( 10, "WEP Network Detected - Passwords can easily be hacked." ) if (network.encryption_type is 'wpa'): return ( 20, "WPA Network Detected - Passwords may be vulnerable.") if (network.encryption_type is 'wpa2'): return (100, "Network encryption appears secure") else: return (100, "Network encryption apperas secure") else: return (0, "No network encryption")
def create_scheme(interface, ssid, passkey): # Save a couple SSID / passkey into Scheme object cell = Cell.where(interface, lambda c: c.ssid == ssid) # Get cell matching SSID if cell: # Delete previous duplicate previous = Scheme.find(interface, ssid) if previous: print "Deleting previous \"%s\" duplicate." % (ssid) previous.delete() # Instanciate Scheme for this Cell scheme = Scheme.for_cell(interface, ssid, cell[0], passkey) print "Saving WiFi scheme \"%s\"." % (ssid) try: scheme.save() return scheme except: print "Scheme could not be saved." pass return False
def log_wifi_data(self): '''collects the robot pose and wifi signal strength + quality and publishes it''' wifi_msg = WifiDiagnostics() wifi_msg.header.stamp = rospy.get_rostime() wifi_msg.header.frame_id = '/map' try: (trans, rot) = self.get_robot_pose() self.robot_pose = (trans, rot) except Exception: if self.robot_pose is None: return (trans, rot) = self.robot_pose wifi_msg.position.x = trans[0] wifi_msg.position.y = trans[1] try: cell = Cell.where('wlan0', self.ssid_filter)[0] except IndexError: wifi_msg.signal.data = 0 wifi_msg.qualityby70.data = 0 else: wifi_msg.signal.data = cell.signal temp = cell.quality.encode("utf8") wifi_msg.qualityby70.data = int(temp.split('/')[0]) self.pub.publish(wifi_msg)
estado = 1 log(1, "Reset ifconfig y dhclient") log(0, "configuracion leida.") except: # error. log(5, "Imposible leer la configuracion" ) wifi = 0 conectado=0 internet=0 estado = 0 wait= 10 elif estado ==1: # buscamos el ssid: try: cell = Cell.where("wlan0", lambda cell: cell.ssid.lower() == wifissid.lower()) if ( cell ==[]): # error. log(3, "Imposible Encontrar la wifissid %s " %wifissid ) wifi = 1 estado = 1 wait = 10 else: log(0, "red -%s- encontrada."%wifissid) wifi = 1 wait = 0.1 estado = 2 except: log(5, "Imposible leer redes wifi error de wlan0" ) wifi = 0 conectado=0
File = file(FILE_REDES_WIFI, 'w') todos = Cell.all("wlan0") for celda in todos: File.write(celda.ssid + "\n") File.close() shutil.copy2(FILE_REDES_WIFI, FILE_SEND_REDES_WIFI) log( 1, "Leidas redes wifi al fichero /tmp/redes_wifi.txt -> send/redes_wifi.txt" ) except: log(4, "Error Listar Redes Wifi.") # buscamos el ssid: try: cell = Cell.where( "wlan0", lambda cell: cell.ssid.lower() == wifissid.lower()) if (cell == []): # error. log(3, "Imposible Encontrar la wifissid %s " % wifissid) wifi = 1 estado = 1 wait = 10 else: log(0, "red -%s- encontrada." % wifissid) wifi = 1 wait = 0.1 estado = 2 except: log(5, "Imposible leer redes wifi error de wlan0") wifi = 0 conectado = 0