diff --git a/wificontrol/hostapd.py b/wificontrol/hostapd.py index 9586667..df912e7 100644 --- a/wificontrol/hostapd.py +++ b/wificontrol/hostapd.py @@ -59,15 +59,20 @@ def start(self): def stop(self): self.execute_command(self.hostapd_control("stop")) + def get_hostap_name(self): + return self.re_search("(?<=^ssid=).*", self.hostapd_path) + def set_hostap_name(self, name='reach'): mac_addr = self.get_device_mac()[-6:] self.replace("^ssid=.*", "ssid={}{}".format(name, mac_addr), self.hostapd_path) - def get_hostap_name(self): - return self.re_search("(?<=^ssid=).*", self.hostapd_path) - def set_hostap_password(self, password): - self.replace("^wpa_passphrase=.*", "wpa_passphrase={}".format(password), self.hostapd_path) + self.replace("^wpa_passphrase=.*", + "wpa_passphrase={}".format(password), self.hostapd_path) + return self.verify_hostap_password(password) + + def verify_hostap_password(self, value): + return self.re_search("(?<=^wpa_passphrase=).*", self.hostapd_path) == value def set_host_name(self, name='reach'): try: diff --git a/wificontrol/wificontrol.py b/wificontrol/wificontrol.py index ac136fc..6c82297 100644 --- a/wificontrol/wificontrol.py +++ b/wificontrol/wificontrol.py @@ -79,7 +79,7 @@ def get_wifi_turned_on(self): return (self.wpasupplicant.started() or self.hotspot.started()) def set_hostap_password(self, password): - self.hotspot.set_hostap_password(password) + return self.hotspot.set_hostap_password(password) def get_device_name(self): return self.hotspot.get_host_name() @@ -92,6 +92,19 @@ def set_device_names(self, name): self.hotspot.set_hostap_name(name) self.hotspot.set_host_name(name) self.wifi.restart_dns() + return self.verify_device_names(name) + + def verify_hostap_name(self, name): + mac_addr = self.hotspot.get_device_mac()[-6:] + return "{}{}".format(name, mac_addr) == self.hotspot.get_hostap_name() + + def verify_device_names(self, name): + verified = False + if name == self.hotspot.get_host_name(): + if name == self.wpasupplicant.get_p2p_name(): + if self.verify_hostap_name(name): + verified = True + return verified def get_status(self): state = self.get_state()