Exemple #1
0
    def deactivate(self):
        """
        Disconnects from the network as configured in this scheme.
        """

        subprocess.check_output(['/sbin/ifdown', self.iface],
                                stderr=subprocess.STDOUT)
Exemple #2
0
 def activate(self):
     """
     Connects to the network as configured in this scheme.
     """
     if platform.system() == "Darwin":
         net_ssid = ""
         net_pass = ""
         if "wireless-essid" in self.options.keys():
             net_ssid = self.options['wireless-essid']
         elif "wpa-ssid" in self.options.keys():
             net_pass = self.options['password']
             net_ssid = self.options['wpa-ssid']
         else:
             net_pass = self.options['password']
             net_ssid = self.options['ssid']
     
         response = ""
         response = subprocess.check_output(['networksetup','-setairportnetwork','en0',net_ssid, net_pass])
         if "Failed to join network" in response:
             print("Could not connect to Wi-Fi network!")
         else:
             print("Wi-Fi Connection established!")
     else:
         if self.encryption_type == 'wpa2-eap':
             response = subprocess.check_output(['wpa_supplicant', '-B', '-i', self.interface, '-Dwext', '-c', '/etc/wpa_supplicant_enterprise.conf'])
             if ("Authentication succeeded" in response) or ("EAP authentication completed successfully" in response):
                 print('Wi-Fi Connection established!')
             else:
                 print('Could not connect to Wi-Fi network!')
         else:
             subprocess.check_call(['/sbin/ifdown', self.interface])
             subprocess.check_call(['/sbin/ifup'] + self.as_args())
Exemple #3
0
    def deactivate(self):
        """
        Disconnects from the network as configured in this scheme.
        """

        subprocess.check_output(['sudo', '/sbin/ifconfig', 'wlan0', 'down'],
                                stderr=subprocess.STDOUT)
Exemple #4
0
	def deactivate(self):
		pid = self.get_pid()
		if pid is None:
			return
		try:
			subprocess.check_output(["kill", pid])
		except subprocess.CalledProcessError as e:
			self._logger.warn("Error while stopping hostapd: {output}".format(output=e.output))
			raise e
Exemple #5
0
    def activate(self):
        """
        Connects to the network as configured in this scheme.
        """

        subprocess.check_output(["/sbin/ifdown", self.interface], stderr=subprocess.STDOUT)
        ifup_output = subprocess.check_output(["/sbin/ifup"] + self.as_args(), stderr=subprocess.STDOUT)

        return self.parse_ifup_output(ifup_output)
Exemple #6
0
    def activate(self):
        """
        Connects to the network as configured in this scheme.
        """

        subprocess.check_output(['ifdown', self.interface],
                                stderr=subprocess.STDOUT)
        subprocess.check_output(['ifup'] + self.as_args(),
                                stderr=subprocess.STDOUT)
Exemple #7
0
    def activate(self):
        """
        Connects to the network as configured in this scheme.
        """

        subprocess.check_output(['/sbin/ifdown', self.interface], stderr=subprocess.STDOUT)
        ifup_output = subprocess.check_output(['/sbin/ifup', self.interface] , stderr=subprocess.STDOUT)
        ifup_output = ifup_output.decode('utf-8')

        return self.parse_ifup_output(ifup_output)
Exemple #8
0
    def activate(self):
        """
        Connects to the network as configured in this scheme.
        """

        subprocess.check_output(['/usr/bin/sudo', '/sbin/ifdown', '-i', self.interfaces, self.interface], stderr=subprocess.STDOUT)
        ifup_output = subprocess.check_output(['/usr/bin/sudo', '/sbin/ifup', '-i', self.interfaces] + self.as_args(), stderr=subprocess.STDOUT)
        ifup_output = ifup_output.decode('utf-8')

        return self.parse_ifup_output(ifup_output)
Exemple #9
0
    def activate(self, sudo=False):
        """
        Connects to the network as configured in this scheme.
        """
        pre = {True: ['sudo'], False: []}[sudo]
        subprocess.check_output(pre + ['/sbin/ifdown', self.interface],
                                stderr=subprocess.STDOUT)
        ifup_output = subprocess.check_output(pre + ['/sbin/ifup'] +
                                              self.as_args(),
                                              stderr=subprocess.STDOUT)
        ifup_output = ifup_output.decode('utf-8')

        return self.parse_ifup_output(ifup_output)
Exemple #10
0
    def activate(self):
        """
		Connects to the network as configured in this scheme.
		"""

        # subprocess.call(['/sbin/ifconfig', self.interface, 'down'])
        # subprocess.call(['service', 'wpa_supplicant', 'restart'])
        # subprocess.call(['/sbin/ifconfig', self.interface, 'up'])
        # subprocess.call(['/sbin/ifconfig', self.interface])
        output = subprocess.check_output(
            ['/sbin/wpa_cli', '-i', self.interface, 'reconfigure'])

        if output.strip() != b'OK':
            raise ConnectionError(
                "Error reconfiguring wpa_supplicant. This is really bad! Check the {} file."
                .format(SchemeWPA.interfaces))

        tries = 0
        while netifaces.AF_INET not in netifaces.ifaddresses(self.interface):
            tries += 1
            if tries > 20:
                raise ConnectionError(
                    "Interface {} did not get an IP address".format(
                        self.interface))
            sleep(0.5)

        return netifaces.ifaddresses(
            self.interface)[netifaces.AF_INET][0]['addr']
Exemple #11
0
    def activate(self):
        """
        Connects to the network as configured in this scheme.
        Returns True if can connect, otherwise returns False
        """

        subprocess.check_output(['/sbin/ifdown', self.interface],
                                stderr=subprocess.STDOUT)
        ifup_output = subprocess.check_output(['/sbin/ifup'] + self.as_args(),
                                              stderr=subprocess.STDOUT)
        ifup_output = ifup_output.decode('utf-8')
        ip = self.wait4ip()
        if ip == "":
            return False
        else:
            return True
Exemple #12
0
    def activate(self):
        """
        Connects to the network as configured in this scheme.
        """
        from .connection import Connection

        subprocess.check_output(['/sbin/ifdown', self.interface],
                                stderr=subprocess.STDOUT)
        output = subprocess.check_output(['/sbin/ifup'] + self.as_args(),
                                         stderr=subprocess.PIPE)
        connection = Connection.current_for_scheme(self)
        if not connection:
            print(output)
            raise ConnectionError("Failed to connect to %r" % self)
        else:
            return connection
Exemple #13
0
    def activate(self, sudo=False):
        """
        Connects to the network as configured in this scheme.
        """

        args_ifdown = ['/sbin/ifdown', self.interface]
        args_ifup = ['/sbin/ifup']
        if sudo:
            args_ifdown.insert(0, 'sudo')
            args_ifup.insert(0, 'sudo')
        subprocess.check_output(args_ifdown, stderr=subprocess.STDOUT)
        ifup_output = subprocess.check_output(args_ifup + self.as_args(),
                                              stderr=subprocess.STDOUT)
        ifup_output = ifup_output.decode('utf-8')

        return self.parse_ifup_output(ifup_output)
Exemple #14
0
    def all(cls, interface):
        """
        Returns a list of all cells extracted from the output of iwlist.
        """
        iwlist_scan = subprocess.check_output(['/sbin/iwlist', interface, 'scan']).decode('utf-8')
        cells = map(Cell.from_string, cells_re.split(iwlist_scan)[1:])

        return cells
Exemple #15
0
    def all(cls, interface):
        """
        Returns a list of all cells extracted from the output of iwlist.
        """
        try:
            iwlist_scan = subprocess.check_output(['/sbin/iwlist', interface, 'scan'],
                                                  stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            try:
                iwlist_scan = subprocess.check_output(['sudo', '-u', 'pi', '/sbin/iwlist', interface, 'scan'],
                                                    stderr=subprocess.STDOUT)
            except subprocess.CalledProcessError as e:
                raise InterfaceError(e.output.strip())
        iwlist_scan = iwlist_scan.decode('utf-8')
        cells = map(Cell.from_string, cells_re.split(iwlist_scan)[1:])

        return cells
Exemple #16
0
	def activate(self):
		try:
			output = subprocess.check_output([self.__class__.hostapd, "-dd", "-B", self.configfile], stderr=subprocess.STDOUT)
			self._logger.info("Started hostapd: {output}".format(output=output))
			return True
		except subprocess.CalledProcessError as e:
			self._logger.warn("Error while starting hostapd: {output}".format(output=e.output))
			raise e
Exemple #17
0
	def activate(self):
		""" Activates this config. """

		try:
			output = subprocess.check_output([self.__class__.dnsmasq, "--conf-file={file}".format(file=self.configfile)], stderr=subprocess.STDOUT)
			self._logger.info("Started dnsmasq: {output}".format(output=output))
		except subprocess.CalledProcessError as e:
			self._logger.warn("Error while starting dnsmasq: {output}".format(output=e.output))
			raise e
Exemple #18
0
    def activate(self):
        """
        Connects to the network as configured in this scheme.
        """

        ifup_output = subprocess.check_output(['/sbin/ifup'] + self.as_args(), stderr=subprocess.STDOUT)
        ifup_output = ifup_output.decode('utf-8')

        return self.parse_ifup_output(ifup_output)
Exemple #19
0
 def activate(self):
     self.deactivate()
     self.save(allow_overwrite=True)
     try:
         ifconfig_output = subprocess.check_output(['/sbin/netctl', 'enable', self.iface], stderr=subprocess.STDOUT)
     except subprocess.CalledProcessError as e:
         self.logger.exception("Error while trying to connect to %s" % self.iface)
         self.logger.error("Output: %s" % e.output)
         raise InterfaceError("Failed to connect to %r: %s" % (self, e.message))
Exemple #20
0
    def all(cls, interface):
        """
        Returns a list of all cells extracted from the output of
        iwlist.
        """
        iwlist_scan = subprocess.check_output(
            ['/sbin/iwlist', interface, 'scan']).decode('utf-8')

        cells = map(normalize, cells_re.split(iwlist_scan)[1:])

        return cells
Exemple #21
0
    def activate(self):
        """
        Connects to the network as configured in this scheme.
        """
        if platform.system() == "Darwin":
            net_ssid = ""
            net_pass = ""
            if "wireless-essid" in self.options.keys():
                net_ssid = self.options['wireless-essid']
            elif "wpa-ssid" in self.options.keys():
                net_pass = self.options['password']
                net_ssid = self.options['wpa-ssid']
            else:
                net_pass = self.options['password']
                net_ssid = self.options['ssid']

            response = ""
            response = subprocess.check_output([
                'networksetup', '-setairportnetwork', 'en0', net_ssid, net_pass
            ])
            if "Failed to join network" in response:
                print("Could not connect to Wi-Fi network!")
            else:
                print("Wi-Fi Connection established!")
        else:
            if self.encryption_type == 'wpa2-eap':
                response = subprocess.check_output([
                    'wpa_supplicant', '-B', '-i', self.interface, '-Dwext',
                    '-c', '/etc/wpa_supplicant_enterprise.conf'
                ])
                if ("Authentication succeeded" in response) or (
                        "EAP authentication completed successfully"
                        in response):
                    print('Wi-Fi Connection established!')
                else:
                    print('Could not connect to Wi-Fi network!')
            else:
                subprocess.check_call(['/sbin/ifdown', self.interface])
                subprocess.check_call(['/sbin/ifup'] + self.as_args())
Exemple #22
0
 def activate(self):
     """
     Connects to the network as configured in this scheme.
     """
     if self.encryption_type == 'wpa2-eap':
         response = subprocess.check_output(['wpa_supplicant', '-B', '-i', self.interface, '-Dwext', '-c', '/etc/wpa_supplicant_enterprise.conf'])
         if ("Authentication succeeded" in response) or ("EAP authentication completed successfully" in response):
             print 'Wi-Fi Connection established!'
         else:
             print 'Could not connect to Wi-Fi network!'
     else:
         subprocess.check_call(['/sbin/ifdown', self.interface])
         subprocess.check_call(['/sbin/ifup'] + self.as_args())
Exemple #23
0
    def all(cls, interface):
        """
        Returns a list of all cells extracted from the output of iwlist.
        """
        try:
            iwlist_scan = subprocess.check_output(
                ['/sbin/iwlist', interface, 'scan'], stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            raise InterfaceError(e.output.strip())
        else:
            iwlist_scan = iwlist_scan.decode('utf-8')
        cells = map(Cell.from_string, cells_re.split(iwlist_scan)[1:])

        return cells
Exemple #24
0
    def current(cls):
        """
        Returns a list of all the schemes that it is possible that are
        currently activated.  May return None if no scheme is currently
        activaated.
        """
        try:
            scheme_name = subprocess.check_output(
                ['/sbin/iwgetid', '--raw', '--scheme'],
                stderr=subprocess.STDOUT).strip().decode('ascii')
        except subprocess.CalledProcessError:
            return None

        return Scheme.where(lambda s: s.ssid == scheme_name)
Exemple #25
0
    def activate(self):
        """
        Connects to the network as configured in this scheme.
        """

        self.deactivate()
        try:
            ifup_output = subprocess.check_output(['/sbin/ifup'] + self.as_args(), stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            self.logger.exception("Error while trying to connect to %s" % self.iface)
            self.logger.error("Output: %s" % e.output)
            raise InterfaceError("Failed to connect to %r: %s" % (self, e.message))
        ifup_output = ifup_output.decode('utf-8')

        return self.parse_ifup_output(ifup_output)
Exemple #26
0
    def activate(self):
        """
        Connects to the network as configured in this scheme.
        """

        self.deactivate()
        try:
            ifup_output = subprocess.check_output(
                ['/sbin/ifconfig', self.interface, 'up'] + self.as_args(),
                stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            self.logger.exception("Error while trying to connect to %s" %
                                  self.iface)
            self.logger.error("Output: %s" % e.output)
            raise InterfaceError("Failed to connect to %r: %s" %
                                 (self, e.message))
        ifup_output = ifup_output.decode('utf-8')

        return self.parse_ifup_output(ifup_output)
Exemple #27
0
 def activate(self):
     """
     Connects to the network as configured in this scheme.
     """
     subprocess.check_output(
         ["sudo", "/sbin/ifconfig", self.interface, "down"],
         stderr=subprocess.STDOUT)
     subprocess.check_output(
         ["sudo", "/sbin/ifconfig", self.interface, "up"],
         stderr=subprocess.STDOUT)
     subprocess.check_output(
         ["sudo", "/sbin/wpa_cli", "-i", self.interface, "reconfigure"],
         stderr=subprocess.STDOUT)
     time.sleep(10)
Exemple #28
0
 def deactivate(self):
     subprocess.check_output(['/usr/bin/sudo', '/sbin/ifdown', '-i', self.interfaces, self.interface], stderr=subprocess.STDOUT)
Exemple #29
0
 def deactivate(self):
     subprocess.check_output(['/sbin/netctl', 'disable', self.iface], stderr=subprocess.STDOUT)
     subprocess.check_output(['/sbin/ifconfig', self.interface, 'down'], stderr=subprocess.STDOUT)
Exemple #30
0
    def deactivate(self):
        """
        Disconnects from the network as configured in this scheme.
        """

        subprocess.check_output(['/sbin/ifdown', self.interface], stderr=subprocess.STDOUT)