from http.server \ import HTTPServer, BaseHTTPRequestHandler import requests import subprocess import datetime class HttpGetHandler(BaseHTTPRequestHandler): def do_GET(self): try: if self.path.endswith("/Status"): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() get = requests.get('https://api.ipify.org/') http_text = f"" \ f"Простой HTTP-сервер." \ f"Ваш адресс {get.text}.
" \ f"'Enter new DNS1 address: x.x.x.x" \ f"
" \ f'' \ f"" self.wfile.write(http_text.encode('utf-8')) except IOError: self.send_error(400, "File not found{self.path}") def do_POST(self): if self.path.endswith("/post"): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() response = self.headers.get('Content-Length') post_body = self.rfile.read(int(response)).decode('utf-8').split('=')[-1] subprocess.call(f'netsh interface ipv4 set dns name="Ethernet" static {post_body} primary', shell=True) http_text = f"" \ f"Ответ" \ f"
DNS адрес изменен" \ f"" self.wfile.write(http_text.encode('utf-8')) def main(server_class=HTTPServer, handler_class=HttpGetHandler): server_address = ('localhost', 8000) httpd = server_class(server_address, handler_class) try: print("есть связь") httpd.serve_forever() except KeyboardInterrupt: httpd.server_close() print("нет связи") if __name__ == '__main__': main()