Ejemplo n.º 1
0
 def test_regset(self):
     self.assertEqual(None,pyw.regset(newregdom))
     time.sleep(0.25) # give sleep time
     self.assertEqual(newregdom,pyw.regget())
     self.assertEqual(None,pyw.regset(regdom))
     time.sleep(0.25) # give sleep time
     self.assertEqual(regdom, pyw.regget())
Ejemplo n.º 2
0
 def test_regset(self):
     self.assertEqual(None, pyw.regset(newregdom))
     time.sleep(0.25)  # give sleep time
     self.assertEqual(newregdom, pyw.regget())
     self.assertEqual(None, pyw.regset(regdom))
     time.sleep(0.25)  # give sleep time
     self.assertEqual(regdom, pyw.regget())
 def get_regulatory_domain(self):
     '''
     Returns the regulatory domain
     '''
     return pyw.regget()
Ejemplo n.º 4
0
 def test_regget(self):
     self.assertEqual(regdom, pyw.regget())
Ejemplo n.º 5
0
 def test_regget(self): self.assertEqual(regdom,pyw.regget())
 def test_regset(self):
Ejemplo n.º 6
0
def execute(dev):
    print('Setting up...')
    # ensure dev is a wireless interfaces
    ifaces = pyw.interfaces()
    wifaces = pyw.winterfaces()
    if dev not in ifaces:
        print("Device {0} is not valid, use one of {1}".format(dev,ifaces))
        return
    elif dev not in wifaces:
        print("Device {0} is not wireless, use one of {1}".format(dev,wifaces))

    # get a Card & info for dev
    print("Regulatory Domain currently: ", pyw.regget())
    dinfo = pyw.devinfo(dev)
    card = dinfo['card']
    pinfo = pyw.phyinfo(card)
    driver = hw.ifdriver(card.dev)
    chipset = hw.ifchipset(driver)

    # bring the card down and change the mac
    pyw.down(card)
    pyw.macset(card,'00:03:93:57:54:46')

    # print details
    msg = "Using {0} currently in mode: {1}\n".format(card,dinfo['mode'])
    msg += "\tDriver: {0} Chipset: {1}\n".format(driver,chipset)
    if dinfo['mode'] == 'managed':
        msg += "\tcurrently on channel {0} width {1}\n".format(rf2ch(dinfo['RF']),
                                                               dinfo['CHW'])
    msg += "\tSupports modes {0}\n".format(pinfo['modes'])
    msg += "\tSupports commands {0}".format(pinfo['commands'])
    msg += "\thw addr {0}".format(pyw.macget(card))
    print(msg)

    # prepare a virtual interface named pent0 in monitor mode
    # delete all ifaces on the phy to avoid interference
    # bring the card up when down
    print('Preparing pent0 for monitor mode')
    pdev = 'pent0'
    pcard = pyw.devadd(card, pdev, 'monitor')
    for iface in pyw.ifaces(card):
        if iface[0].dev != pcard.dev:
            print("deleting {0} in mode {1}".format(iface[0],iface[1]))
            pyw.devdel(iface[0])
    pyw.up(pcard)
    print("Using", pcard)

    print("Setting channel to 6 NOHT")
    pyw.chset(pcard,6,None)
    msg = "Virtual interface {0} in monitor mode on ch 6".format(pcard)
    print(msg + ", using hwaddr: {0}".format(pyw.macget(pcard)))

    # DO stuff here
    try:
        print('Now ready to do stuff')
        print('For example, run wireshark to verify card is seeing all packets')
        print('Hit Ctrl-C to quit and restore')
        while True: time.sleep(1)
    except KeyboardInterrupt:
        pass

    # restore original
    print('Restoring', card, 'mode =', dinfo['mode'], 'mac =', dinfo['mac'])
    card = pyw.devadd(pcard,card.dev,dinfo['mode'])
    print('Deleting', pcard)
    pyw.devdel(pcard)
    pyw.macset(card,dinfo['mac'])
    pyw.up(card)
    print("card ", card, " restored")
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
def execute(dev):
    print('Setting up...')
    # ensure dev is a wireless interfaces
    ifaces = pyw.interfaces()
    wifaces = pyw.winterfaces()
    if dev not in ifaces:
        print("Device {0} is not valid, use one of {1}".format(dev, ifaces))
        return
    elif dev not in wifaces:
        print("Device {0} is not wireless, use one of {1}".format(
            dev, wifaces))

    # get a Card & info for dev
    print("Regulatory Domain currently: ", pyw.regget())
    dinfo = pyw.devinfo(dev)
    card = dinfo['card']
    pinfo = pyw.phyinfo(card)
    driver = hw.ifdriver(card.dev)
    chipset = hw.ifchipset(driver)

    # bring the card down and change the mac
    pyw.down(card)
    pyw.macset(card, '00:03:93:57:54:46')

    # print details
    msg = "Using {0} currently in mode: {1}\n".format(card, dinfo['mode'])
    msg += "\tDriver: {0} Chipset: {1}\n".format(driver, chipset)
    if dinfo['mode'] == 'managed':
        msg += "\tcurrently on channel {0} width {1}\n".format(
            rf2ch(dinfo['RF']), dinfo['CHW'])
    msg += "\tSupports modes {0}\n".format(pinfo['modes'])
    msg += "\tSupports commands {0}".format(pinfo['commands'])
    msg += "\thw addr {0}".format(pyw.macget(card))
    print(msg)

    # prepare a virtual interface named pent0 in monitor mode
    # delete all ifaces on the phy to avoid interference
    # bring the card up when down
    print('Preparing pent0 for monitor mode')
    pdev = 'pent0'
    pcard = pyw.devadd(card, pdev, 'monitor')
    for iface in pyw.ifaces(card):
        if iface[0].dev != pcard.dev:
            print("deleting {0} in mode {1}".format(iface[0], iface[1]))
            pyw.devdel(iface[0])
    pyw.up(pcard)
    print("Using", pcard)

    print("Setting channel to 6 NOHT")
    pyw.chset(pcard, 6, None)
    msg = "Virtual interface {0} in monitor mode on ch 6".format(pcard)
    print(msg + ", using hwaddr: {0}".format(pyw.macget(pcard)))

    # DO stuff here
    try:
        print('Now ready to do stuff')
        print(
            'For example, run wireshark to verify card is seeing all packets')
        print('Hit Ctrl-C to quit and restore')
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass

    # restore original
    print('Restoring', card, 'mode =', dinfo['mode'], 'mac =', dinfo['mac'])
    card = pyw.devadd(pcard, card.dev, dinfo['mode'])
    print('Deleting', pcard)
    pyw.devdel(pcard)
    pyw.macset(card, dinfo['mac'])
    pyw.up(card)
    print("card ", card, " restored")
Ejemplo n.º 9
0
 def get_current_wifi_country(self):
     return pyw.regget()
Ejemplo n.º 10
0
    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