|
@@ -0,0 +1,58 @@
|
|
|
|
+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"<html><head><meta charset = 'utf-8'>" \
|
|
|
|
+ f"<title>Простой HTTP-сервер.</title></head>" \
|
|
|
|
+ f"<body>Ваш адресс {get.text}.<br>" \
|
|
|
|
+ f"<body>'Enter new DNS1 address: x.x.x.x" \
|
|
|
|
+ f"<form action=/post method=POST>" \
|
|
|
|
+ f'<input type="text" id="dns_form1" name="dns1">' \
|
|
|
|
+ f"</body></html>"
|
|
|
|
+
|
|
|
|
+ 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"<html><head><meta charset = 'utf-8'>" \
|
|
|
|
+ f"<title>Ответ</title></head>" \
|
|
|
|
+ f"<br>DNS адрес изменен" \
|
|
|
|
+ f"</body></html>"
|
|
|
|
+
|
|
|
|
+ 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()
|