def set_unmanaged_by_network_manager(cls, interface): Logger.debug( "Adding interface \"%s-%s\" as an unmanaged interface to network manager", interface, cls.get_mac(interface)) with open(constants.PATH_CONF_NETWORK_MANAGER, "r") as conf_read: conf = conf_read.read().splitlines() added = False entry = "mac:" + cls.get_mac(interface) # Add Entry for line in range(0, len(conf)): # Add keyfile plugin if it's not enabled if conf[line].startswith( "plugins=") and "keyfile" not in conf[line]: conf[line] += ",keyfile" # Add unmanaged device if conf[line].startswith( "unmanaged-devices=") and entry not in conf[line]: conf[line] += ";" + entry added = True # Add the initial unmanaged entry if it was not present if not added: conf.append("[keyfile]") conf.append("unmanaged-devices=" + entry) # Write with open(constants.PATH_CONF_NETWORK_MANAGER, "w") as conf_write: for line in conf: conf_write.write(line + "\n") # Restart the service ProcessUtil.call(["service", "network-manager", "restart"]) ProcessUtil.call(["service", "networking", "restart"])
def stop(self): LoggerCli.info("Stopping") ProcessUtil.call(["killall", "dhclient"]) self.getting_key = False if self.drc_sim_c: self.drc_sim_c.stop() if self.wpa_supplicant: self.wpa_supplicant.stop()
def is_interface_wiiu_compatible(cls, interface): if not OsUtil.is_linux(): Logger.extra("Ignoring interface compatibility check for %s", interface) return False frequency_info = ProcessUtil.get_output( ["iwlist", interface, "frequency"]) return "5." in frequency_info
def wpa_cli(command): """ Makes a system call to wpa_cli_drc :param command: command to pass to wpa_cli_drc :return: command output """ if isinstance(command, str): command = [command] return ProcessUtil.get_output( ["wpa_cli_drc", "-p", "/var/run/wpa_supplicant_drc"] + command, silent=True)
def get_device_unmanaged_entry(cls, interface): # Ubuntu 17.04+ and any other Distro after 2017 randomizes the MAC address of the device each time network manager restarts. # No Python Library is able to get the Hardware Address so I needed to use a Linux Command hwaddress = ProcessUtil.get_output(["ethtool", "-P", interface]) hwaddressstr = hwaddress[-18:] return "interface-name:" + interface + ";mac:" + hwaddressstr
def dhclient(cls, interface): ProcessUtil.call(["killall", "dhclient"]) ProcessUtil.call(["dhclient", interface])
def set_metric(cls, interface, metric): ProcessUtil.call(["ifmetric", interface, str(metric)])
def unblock_wlan(): """ Make a system call to unblock wlan :return: None """ ProcessUtil.call(["rfkill", "unblock", "wlan"])
def kill_wpa(): """ Makes a system call to kill wpa_supplicant_drc :return: None """ ProcessUtil.call(["killall", "wpa_supplicant_drc"])
def kill_drc_sim_c(): ProcessUtil.call(["killall", "drc_sim_c"])