def setup_card(interface_name, frequency, data_rate=2): print("Settings up " + interface_name) wifi_card = pyw.getcard(interface_name) driver_name = iwhw.ifdriver(interface_name) if driver_name in EXPERIMENTAL_DRIVERS: print("Warning: Using WiFi adapter with experimental support!") print("Setting " + wifi_card.dev + " " + driver_name + " " + str(frequency) + " MHz" + " bitrate: " + get_bit_rate(data_rate) + " Mbps") if not pyw.isup(wifi_card): print("\tup...") pyw.up(wifi_card) if is_atheros_card(driver_name): # for all other cards the transmission rate is set via the radiotap header set_bitrate(interface_name, data_rate) if pyw.isup(wifi_card): print("\tdown...") pyw.down(wifi_card) print("\tmonitor...") pyw.modeset(wifi_card, 'monitor') if is_realtek_card(driver_name): # Other cards power settings are set via e.g. 'txpower_atheros 58' or 'txpower_ralink 0' (defaults) pyw.txset(wifi_card, 'fixed', 3000) if not pyw.isup(wifi_card): print("\tup...") pyw.up(wifi_card) print("\tfrequency...") pyw.freqset(wifi_card, frequency) print("\tMTU...") if is_realtek_card(driver_name): subprocess.run(['ip link set dev ' + interface_name + ' mtu 1500'], shell=True) else: subprocess.run(['ip link set dev ' + interface_name + ' mtu 2304'], shell=True) pyw.regset('DE') # to allow channel 12 and 13 for hotspot rename_interface(interface_name)
def is_wifi_present(): wlan = pyw.winterfaces() if len(wlan) >= 1: interface = wlan[0] if pyw.isinterface(interface): card = pyw.getcard(interface) info = pyw.ifinfo(card) if pyw.isup(card) is not True: print("Turn On wifi Actual estate:", pyw.isup(card)) wifi_info = {'wifi': interface, 'card': pyw.isup(card), 'mac': pyw.macget(card), 'driver': info.get('driver'), 'chip': info.get('chipset'), 'man': info.get('manufacturer'), 'con': to_json(get_all_info())} print(texto.safe_substitute(wifi_info)) else: wifi_info = {'wifi': interface, 'card': pyw.isup(card), 'mac': pyw.macget(card), 'driver': info.get('driver'), 'chip': info.get('chipset'), 'man': info.get('manufacturer'), 'con': to_json(get_all_info())} print(texto.safe_substitute(wifi_info)) else: print('wifi no encobtrado')
def set_monitor_mode(interface: Union[str, pyw.Card]) -> pyw.Card: interface = _get_card(interface) if pyw.modeget(interface) != "monitor": if pyw.isup(interface): pyw.down(interface) pyw.modeset(interface, "monitor") if not pyw.isup(interface): pyw.up(interface) return interface
def getInfo(card_name): """ Returns the dict containing info regarding the wireless card. Dict : {name, channel, ipv4, mac, status} Arguments : card_name -- name of the wireless card """ c = pyw.getcard(card_name) channel = Wireless.getChannel(card_name) status = "" if pyw.isup(c): status = "up" else: status = "down" # one of this function disables during root so autload whichever available. ipv4 = None if "inetget" in dir(pyw): ipv4 = pyw.inetget(c)[0] elif "ifaddrget" in dir(pyw): ipv4 = pyw.ifaddrget(c)[0] mac = pyw.macget(c) return { "name": str(card_name), "channel": str(channel), "ipv4": str(ipv4), "mac": str(mac), "status": str(status) }
def set_interface_up(self, ifaceName): card = self.get_wifi_chard(ifaceName) # get a card for interface # TODO: replace by pyric rfkill cmd = "rfkill unblock wifi" self.run_command(cmd) pyw.up(card) return pyw.isup(card)
def __enter__(self): if not pyw.isup(self.wlan_if): pyw.up(self.wlan_if) return True # Good to go if it's already active, but not otherwise return self.initial_state == self.STATE_ACTIVE
def set_monitor_mode(interface): """ Set interface in mode monitor an set channel 1 """ interface = pyw.getcard(interface) if pyw.modeget(interface) != "monitor": if pyw.isup(interface): pyw.down(interface) pyw.modeset(interface, "monitor") if not pyw.isup(interface): pyw.up(interface) if pyw.chget(interface) != 1: pyw.chset(interface, 1)
def DebuggingInterface(iface): interfaces = pyw.interfaces() print(interfaces) print(("Is %s an interface? %s" % (iface, pyw.isinterface(iface)))) print(("Is %s a wireless device? %s" % (iface, pyw.iswireless(iface)))) w0 = pyw.getcard(iface) print(("Is %s active? %s" % (iface, pyw.isup(w0)))) print(("Is %s blocked? %s" % (iface, pyw.isblocked(w0)))) iinfo = pyw.ifinfo(w0) print(iinfo) pinfo = pyw.phyinfo(w0) print((pinfo['bands']))
def interface_command(interface, verbose): faces = pyw.winterfaces() if interface == "all" else [interface] for face in faces: if face not in pyw.winterfaces(): sys.exit(f"{face} is not an interface") print(f"{Fore.GREEN}Interfaces:{Fore.YELLOW}") for interface in faces: face = pyw.getcard(interface) up = Fore.YELLOW if pyw.isup(face) else Fore.RED print(f" {up}{interface:<10} {Style.RESET_ALL}") if verbose >= 1: iinfo = pyw.ifinfo(face) for i in iinfo: print( f"\t{i.title():<15} {Fore.CYAN}{iinfo[i]}{Style.RESET_ALL}" ) if verbose >= 2: dinfo = pyw.devinfo(face) for d in dinfo: print( f"\t{d.title():<15} {Fore.CYAN}{dinfo[d]}{Style.RESET_ALL}" ) if verbose >= 3: pinfo = pyw.phyinfo(face) for p in pinfo: if type(pinfo[p]) == list: print( f"\t{p.title():<15} {Fore.CYAN}{', '.join(pinfo[p])}{Style.RESET_ALL}" ) elif p == "bands": print( f"\t{p.title():<15} {Fore.CYAN}{', '.join(pinfo[p].keys())}{Style.RESET_ALL}" )
def test_up(self): self.assertEqual(None,pyw.up(self.card)) self.assertTrue(pyw.isup(self.card))
def __init__(self, wlan_if): self.wlan_if = wlan_if if pyw.isup(self.wlan_if): self.initial_state = self.STATE_ACTIVE else: self.initial_state = self.STATE_INACTIVE
def is_interface_up(self, ifaceName): w0 = self.get_wifi_chard(ifaceName) # get a card for interface return pyw.isup(w0)
def is_enable(self, interface): return pyw.isup(interface)
def test_down(self): self.assertEqual(None, pyw.down(self.card)) self.assertFalse(pyw.isup(self.card))
def test_up(self): self.assertEquals(None, pyw.up(self.card)) self.assertTrue(pyw.isup(self.card))
def test_down(self): self.assertEqual(None,pyw.down(self.card)) self.assertFalse(pyw.isup(self.card))
def is_up(self): try: w = pyw.getcard(self._interface) return pyw.isup(w) except pyric.error as e: logger.error(e)
def getinfo(self): try: self.data['macaddress'] = netifaces.ifaddresses(self._if)[netifaces.AF_LINK][0]['addr'] except: self.data['macaddress'] = None try: self.data['ipaddress'] = netifaces.ifaddresses(self._if)[netifaces.AF_INET][0]['addr'] except: self.data['ipaddress'] = None try: self.data['vendorstr'] = self.udevnet.data[self._if+"_id_vendor_from_database"] except: self.data['vendorstr'] = None try: self.data['vendoroui'] = self.udevnet.data[self._if+"_id_oui_from_database"] except: self.data['vendoroui'] = None try: self.data['vendor'] = self.udevnet.data[self._if+"_id_vendor"] except: self.data['vendor'] = None # Hack for onboard raspberry devices if type(self.data['vendoroui']) is str: if re.search("^Raspberry", self.data['vendoroui']): self.data['vendor'] = "RaspberryPi" try: self.data['driver'] = self.udevnet.data[self._if+"_id_net_driver"] except: try: self.data['driver'] = self.udevnet.data[self._if+"_id_usb_driver"] except: self.data['driver'] = None try: self.data['model'] = self.udevnet.data[self._if+"_id_model_id"] except: self.data['model'] = None try: self.data['modelstr'] = self.udevnet.data[self._if+"_id_model_from_database"] except: self.data['modelstr'] = None try: self.data['netname'] = self.udevnet.data[self._if+"_id_net_name_from_database"] except: try: self.data['netname'] = self.udevnet.data[self._if+"_id_net_name_onboard"] except: try: self.data['netname'] = self.udevnet.data[self._if+"_id_net_name_slot"] except: try: self.data['netname'] = self.udevnet.data[self._if+"_id_net_name_path"] except: try: self.data['netname'] = self.udevnet.data[self._if+"_id_net_name_mac"] except: self.data['netname'] = None try: self.data['type'] = self.udevnet.data[self._if+"_devtype"] if self.data['type'] == "wlan": self.data['type'] = "Wireless" except: try: if re.search("^en", self.data['netname']): self.data['type'] = "Ethernet" elif re.search("^wl", self.data['netname']): self.data['type'] = "Wireless" else: self.data['type'] = None except: self.data['type'] = None # Stop here if we don't have a wireless card if self.data['type'] != "Wireless": return # Retrieve wireless info try: _ifobj = pyw.getcard(self._if) _ifinfo = pyw.ifinfo(_ifobj) _devinfo = pyw.devinfo(_ifobj) _physinfo = pyw.phyinfo(_ifobj) _linkinfo = pyw.link(_ifobj) except: pass try: self.data['isup'] = pyw.isup(_ifobj) except: self.data['isup'] = None try: self.data['blocked'] = pyw.isblocked(_ifobj) except: self.data['blocked'] = None try: self.data['mode'] = _devinfo['mode'] except: self.data['mode'] = None try: self.data['modes'] = _physinfo['modes'] except: self.data['modes'] = None try: self.data['bands'] = _physinfo['bands'] except: self.data['bands'] = None try: self.data['standards'] = pyw.devstds(_ifobj) except: self.data['standards'] = None try: self.data['freqs'] = pyw.devfreqs(_ifobj) except: self.data['freqs'] = None try: self.data['txpower'] = pyw.txget(_ifobj) except: self.data['txpower'] = None try: self.data['chans'] = pyw.devchs(_ifobj) except: self.data['chans'] = None try: self.data['reg'] = pyw.regget(_ifobj) except: self.data['reg'] = None try: self.data['chipset'] = _ifinfo['chipset'] except: self.data['chipset'] = None try: self.data['state'] = _linkinfo['stat'] except: self.data['state'] = None try: self.data['ssid'] = _linkinfo['ssid'] except: self.data['ssid'] = None try: self.data['chw'] = _devinfo['CHW'] except: self.data['chw'] = None try: self.data['frequency'] = _devinfo['RF'] except: self.data['frequency'] = None try: self.data['rss'] = _linkinfo['rss'] except: self.data['rss'] = None try: self.data['wtx'] = _linkinfo['tx'] except: self.data['wtx'] = None try: self.data['wrx'] = _linkinfo['rx'] except: self.data['wrx'] = None
def getinfo(self): try: self.data['macaddress'] = netifaces.ifaddresses( self._if)[netifaces.AF_LINK][0]['addr'] except: self.data['macaddress'] = None try: self.data['ipaddress'] = netifaces.ifaddresses( self._if)[netifaces.AF_INET][0]['addr'] except: self.data['ipaddress'] = None try: self.data['vendorstr'] = self.udevnet.data[ self._if + "_id_vendor_from_database"] except: self.data['vendorstr'] = None try: self.data['vendoroui'] = self.udevnet.data[self._if + "_id_oui_from_database"] except: self.data['vendoroui'] = None try: self.data['vendor'] = self.udevnet.data[self._if + "_id_vendor"] except: self.data['vendor'] = None # Hack for onboard raspberry devices if type(self.data['vendoroui']) is str: if re.search("^Raspberry", self.data['vendoroui']): self.data['vendor'] = "RaspberryPi" try: self.data['driver'] = self.udevnet.data[self._if + "_id_net_driver"] except: try: self.data['driver'] = self.udevnet.data[self._if + "_id_usb_driver"] except: self.data['driver'] = None try: self.data['model'] = self.udevnet.data[self._if + "_id_model_id"] except: self.data['model'] = None try: self.data['modelstr'] = self.udevnet.data[ self._if + "_id_model_from_database"] except: self.data['modelstr'] = None try: self.data['netname'] = self.udevnet.data[ self._if + "_id_net_name_from_database"] except: try: self.data['netname'] = self.udevnet.data[ self._if + "_id_net_name_onboard"] except: try: self.data['netname'] = self.udevnet.data[ self._if + "_id_net_name_slot"] except: try: self.data['netname'] = self.udevnet.data[ self._if + "_id_net_name_path"] except: try: self.data['netname'] = self.udevnet.data[ self._if + "_id_net_name_mac"] except: self.data['netname'] = None try: self.data['type'] = self.udevnet.data[self._if + "_devtype"] if self.data['type'] == "wlan": self.data['type'] = "Wireless" except: try: if re.search("^en", self.data['netname']): self.data['type'] = "Ethernet" elif re.search("^wl", self.data['netname']): self.data['type'] = "Wireless" else: self.data['type'] = None except: self.data['type'] = None # Stop here if we don't have a wireless card if self.data['type'] != "Wireless": return # Retrieve wireless info try: _ifobj = pyw.getcard(self._if) _ifinfo = pyw.ifinfo(_ifobj) _devinfo = pyw.devinfo(_ifobj) _physinfo = pyw.phyinfo(_ifobj) _linkinfo = pyw.link(_ifobj) except: pass try: self.data['isup'] = pyw.isup(_ifobj) except: self.data['isup'] = None try: self.data['blocked'] = pyw.isblocked(_ifobj) except: self.data['blocked'] = None try: self.data['mode'] = _devinfo['mode'] except: self.data['mode'] = None try: self.data['modes'] = _physinfo['modes'] except: self.data['modes'] = None try: self.data['bands'] = _physinfo['bands'] except: self.data['bands'] = None try: self.data['standards'] = pyw.devstds(_ifobj) except: self.data['standards'] = None try: self.data['freqs'] = pyw.devfreqs(_ifobj) except: self.data['freqs'] = None try: self.data['txpower'] = pyw.txget(_ifobj) except: self.data['txpower'] = None try: self.data['chans'] = pyw.devchs(_ifobj) except: self.data['chans'] = None try: self.data['reg'] = pyw.regget(_ifobj) except: self.data['reg'] = None try: self.data['chipset'] = _ifinfo['chipset'] except: self.data['chipset'] = None try: self.data['state'] = _linkinfo['stat'] except: self.data['state'] = None try: self.data['ssid'] = _linkinfo['ssid'] except: self.data['ssid'] = None try: self.data['chw'] = _devinfo['CHW'] except: self.data['chw'] = None try: self.data['frequency'] = _devinfo['RF'] except: self.data['frequency'] = None try: self.data['rss'] = _linkinfo['rss'] except: self.data['rss'] = None try: self.data['wtx'] = _linkinfo['tx'] except: self.data['wtx'] = None try: self.data['wrx'] = _linkinfo['rx'] except: self.data['wrx'] = None
def upcard(self): card = pyw.getcard(self.adapter) if not pyw.isup(card): pyw.up(card)