def activate(self):
# 1. Сразу определяем адаптер внутри метода
self.active_adapter = self.get_active_adapter()
url = self.dns_input.get()
self.status_label.configure(text="Настройка...", text_color="yellow")
try:
# Резолвим IP
host = url.replace("https://", "").split("/")[0]
ip = socket.gethostbyname(host)
doh_url = url if "://" in url else f"https://{url}/dns-query"
# Выполняем команды через наш self.active_adapter
cmd1 = f'powershell "Add-DnsClientDohServerAddress -ServerAddress {ip} -DohTemplate \'{doh_url}\' -AllowFallbackToUdp $false -ErrorAction SilentlyContinue"'
cmd2 = f'powershell "Set-DnsClientServerAddress -InterfaceAlias \'{self.active_adapter}\' -ServerAddresses {ip}"'
cmd3 = f'powershell "Set-DnsClient -InterfaceAlias \'{self.active_adapter}\' -UseDnsOverHttps Only"'
subprocess.run(cmd1, shell=True)
subprocess.run(cmd2, shell=True)
subprocess.run(cmd3, shell=True)
subprocess.run('ipconfig /flushdns', shell=True)
self.status_label.configure(text="Статус: АКТИВНО", text_color="green")
self.save_config("Активно")
except Exception as e:
self.status_label.configure(text=f"Ошибка: {str(e)}", text_color="red")
def reset(self):
# И тут тоже сначала определяем, потом юзаем
self.active_adapter = self.get_active_adapter()
try:
subprocess.run(f'powershell Set-DnsClientServerAddress -InterfaceAlias \'{self.active_adapter}\' -ResetServerAddresses', shell=True)
subprocess.run(f'powershell Set-DnsClient -InterfaceAlias \'{self.active_adapter}\' -UseDnsOverHttps Prohibit', shell=True)
subprocess.run('ipconfig /flushdns', shell=True)
self.status_label.configure(text="Статус: Сброшено", text_color="white")
self.save_config("Отключено")
except:
self.status_label.configure(text="Ошибка сброса", text_color="red")