def deactivate(self): """ Disconnects from the network as configured in this scheme. """ subprocess.check_output(['/sbin/ifdown', self.iface], stderr=subprocess.STDOUT)
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())
def deactivate(self): """ Disconnects from the network as configured in this scheme. """ subprocess.check_output(['sudo', '/sbin/ifconfig', 'wlan0', 'down'], stderr=subprocess.STDOUT)
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
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)
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)
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)
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)
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)
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']
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
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
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)
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
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
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
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
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)
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))
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
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())
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())
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
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)
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)
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)
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)
def deactivate(self): subprocess.check_output(['/usr/bin/sudo', '/sbin/ifdown', '-i', self.interfaces, self.interface], stderr=subprocess.STDOUT)
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)
def deactivate(self): """ Disconnects from the network as configured in this scheme. """ subprocess.check_output(['/sbin/ifdown', self.interface], stderr=subprocess.STDOUT)