Exemple #1
0
    def __init__(self, iface, verbose=False, wpa_driver='wext'):
        """ Initialise the wireless network interface class.

        Keyword arguments:
        iface -- name of the interface
        verbose -- print all commands

        """
        BaseWirelessInterface.__init__(self, iface, verbose, wpa_driver)
        Interface.__init__(self, iface, verbose)
Exemple #2
0
    def __init__(self, iface, verbose=False, wpa_driver='wext'):
        """Initialise the wireless network interface class.

        Keyword arguments:
        iface -- name of the interface
        verbose -- print all commands

        """
        BaseWirelessInterface.__init__(self, iface, verbose, wpa_driver)
        Interface.__init__(self, iface, verbose)
Exemple #3
0
    def __init__(self, iface, verbose=False, wpa_driver="wext"):
        """ Initialise the wireless network interface class.

        Keyword arguments:
        iface -- name of the interface
        verbose -- print all commands

        """
        BaseWirelessInterface.__init__(self, iface, verbose, wpa_driver)
        Interface.__init__(self, iface, verbose)
        self.scan_iface = None
        self.CheckWirelessTools()
Exemple #4
0
    def GetNetworks(self, essid=None):
        """Get a list of available wireless networks.

        NOTE: the essid parameter is not used here,
        it was added for the iwlist scan for hidden networks.

        Returns:
        A list containing available wireless networks.

        """
        if not IWSCAN_AVAIL:
            # Use the slow version if python-iwscan isn't available.
            return BaseWirelessInterface.GetNetworks(self)

        if not self.scan_iface:
            try:
                self.scan_iface = iwscan.WirelessInterface(self.iface)
            except iwscan.error as e:
                print(("GetNetworks caught an exception: %s" % e))
                return []

        try:
            results = self.scan_iface.Scan()
        except iwscan.error as e:
            print(("ERROR: %s" % e))
            return []
        return [_f for _f in [self._parse_ap(cell) for cell in results] if _f]
Exemple #5
0
    def GetNetworks(self):
        """ Get a list of available wireless networks.

        Returns:
        A list containing available wireless networks.

        """
        print("IWSCAN_AVAIL {0}".format(IWSCAN_AVAIL))
        if not IWSCAN_AVAIL:
            # Use the slow version if python-iwscan isn't available.
            return BaseWirelessInterface.GetNetworks(self)

        if not self.scan_iface:
            try:
                self.scan_iface = iwscan.WirelessInterface(self.iface)
            except iwscan.error as e:
                print("GetNetworks caught an exception: {0}".format(e))
                return []

        try:
            results = self.scan_iface.Scan()
        except iwscan.error as e:
            print("ERROR: {0}".format(e))
            return []
        print("result {0}".format(results))
        return filter(None, [self._parse_ap(cell) for cell in results])
Exemple #6
0
 def StopWPA(self):
     """Terminates wpa_supplicant using its ctrl interface."""
     if not WPACTRL_AVAIL:
         return BaseWirelessInterface.StopWPA(self)
     wpa = self._connect_to_wpa_ctrl_iface()
     if not wpa:
         return
     wpa.request("TERMINATE")
Exemple #7
0
    def GetNetworks(self):
        """ Get a list of available wireless networks.

        Returns:
        A list containing available wireless networks.

        """
        if not IWSCAN_AVAIL:
            # Use the slow version if python-iwscan isn't available.
            return BaseWirelessInterface.GetNetworks(self)

        if not self.scan_iface:
            try:
                self.scan_iface = iwscan.WirelessInterface(self.iface)
            except iwscan.error, e:
                print "GetNetworks caught an exception: %s" % e
                return []
Exemple #8
0
    def GetNetworks(self, essid=None):
        """ Get a list of available wireless networks.
	
        NOTE: the essid parameter is not used here,
        it was added for the iwlist scan for hidden networks.

        Returns:
        A list containing available wireless networks.

        """
        if not IWSCAN_AVAIL:
            # Use the slow version if python-iwscan isn't available.
            return BaseWirelessInterface.GetNetworks(self)

        if not self.scan_iface:
            try:
                self.scan_iface = iwscan.WirelessInterface(self.iface)
            except iwscan.error, e:
                print "GetNetworks caught an exception: %s" % e
                return []
Exemple #9
0
    def ValidateAuthentication(self, auth_time):
        """Validate WPA authentication.

            Validate that the wpa_supplicant authentication
            process was successful.

            NOTE: It's possible this could return False,
            though in reality wpa_supplicant just isn't
            finished yet.

            Keyword arguments:
            auth_time -- The time at which authentication began.

            Returns:
            True if wpa_supplicant authenticated succesfully,
            False otherwise.

        """
        if not WPACTRL_AVAIL:
            # If we don't have python-wpactrl, use the slow version.
            return BaseWirelessInterface.ValidateAuthentication(
                self, auth_time)

        # Right now there's no way to do this for ralink drivers
        if self.wpa_driver == RALINK_DRIVER:
            return True

        wpa = self._connect_to_wpa_ctrl_iface()
        if not wpa:
            print("Failed to open ctrl interface")
            return False

        MAX_TIME = 35
        MAX_DISCONNECTED_TIME = 3
        disconnected_time = 0
        while (time.time() - auth_time) < MAX_TIME:
            try:
                status = wpa.request("STATUS").split("\n")
            except Exception:
                print("wpa_supplicant status query failed.")
                return False

            if self.verbose:
                print(f'wpa_supplicant ctrl_interface status query is '
                      f'{status}')

            try:
                [result] = [s for s in status if s.startswith("wpa_state=")]
            except ValueError:
                return False

            if result.endswith("COMPLETED"):
                return True
            elif result.endswith("DISCONNECTED"):
                disconnected_time += 1
                if disconnected_time > MAX_DISCONNECTED_TIME:
                    # Force a rescan to get wpa_supplicant moving again.
                    wpa.request("SCAN")
                    MAX_TIME += 5
            else:
                disconnected_time = 0
            time.sleep(1)

        print('wpa_supplicant authentication may have failed.')
        return False