Exemplo n.º 1
0
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')
Exemplo n.º 2
0
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']))
Exemplo n.º 3
0
def setup_hotspot(interface):
    if interface == 'internal':
        interface = PI3_WIFI_NIC
    if pyw.isinterface(HOTSPOT_NIC):
        interface = HOTSPOT_NIC  # check if we already setup a hot spot
    if pyw.isinterface(interface):
        card = pyw.getcard(interface)
        pyw.down(card)
        subprocess.run(["ip link set " + card.dev + " name " + HOTSPOT_NIC], shell=True)
        time.sleep(1)
        card = pyw.getcard(HOTSPOT_NIC)
        pyw.up(card)
        pyw.inetset(card, '192.168.2.1')
        subprocess.run(["udhcpd -I 192.168.2.1 " + os.path.join(DRONEBRIDGE_BIN_PATH, "udhcpd-wifi.conf")], shell=True,
                       stdout=DEVNULL)
        subprocess.run(
            ["dos2unix -n " + os.path.join(DRONEBRIDGE_SETTINGS_PATH, "apconfig.txt") + " /tmp/apconfig.txt"],
            shell=True, stdout=DEVNULL)
        subprocess.Popen(["hostapd", "/tmp/apconfig.txt"], shell=False)
        print("Setup wifi hotspot: " + card.dev + " AP-IP: 192.168.2.1")
    else:
        print("Error: Could not find AP-adapter: " + str(interface) + ", unable to enable access point")
Exemplo n.º 4
0
def rename_interface(orig_interface_name):
    """
    Changes the name of the interface to its mac address

    :param orig_interface_name: The interface that you want to rename
    """
    if pyw.isinterface(orig_interface_name):
        wifi_card = pyw.getcard(orig_interface_name)
        pyw.down(wifi_card)
        new_name = pyw.macget(wifi_card).replace(':', '')
        print(f"\trenaming {orig_interface_name} to {new_name}")
        subprocess.run(['ip link set ' + orig_interface_name + ' name ' + new_name], shell=True)
        wifi_card = pyw.getcard(new_name)
        pyw.up(wifi_card)
    else:
        print("Error: Interface " + str(orig_interface_name) + " does not exist. Cannot rename")
Exemplo n.º 5
0
    def set_scan_adapter(self, value):
        """ wireless adapter being used to scan / inject """
        if value:
            value = value.encode('ascii')
        else:
            value = None

        if value and pyw.isinterface(value):
            card = pyw.getcard(value)
            if 'monitor' not in pyw.devmodes(card):
                raise Exception(
                    "Error, adapter: {} cannot perform monitor mode".format(
                        value))
        elif value:
            LOG.error("Invalid Card detected: {}, saving None to config")
            value = None
        config = cfg.get_config()
        config[cfg.FIELD_ADAPTER_SCAN] = value
        cfg.write_config(config)
Exemplo n.º 6
0
 def test_not_isinterface(self):
     for inic in inics:
         self.assertFalse(pyw.isinterface(inic))
Exemplo n.º 7
0
 def test_isinterface(self):
     for nic in pyw.interfaces():
         self.assertTrue(pyw.isinterface(nic))
Exemplo n.º 8
0
 def test_not_isinterface(self):
     for inic in inics: self.assertFalse(pyw.isinterface(inic))
Exemplo n.º 9
0
 def test_isinterface(self):
     for nic in pyw.interfaces(): self.assertTrue(pyw.isinterface(nic))
Exemplo n.º 10
0
def test_isinterface_is_interface():
    """Test isinterfaces function when device is an interface."""
    assert isinterface("valid_interface")
Exemplo n.º 11
0
def test_isinterface_no_interface():
    """Test isinterfaces function when device is not an interface."""
    assert not isinterface("SomeDevice")
Exemplo n.º 12
0
def is_internet_there():
    internet = pyw.interfaces()
    internet = internet[0]

    return pyw.isinterface(internet)