|
@@ -1,48 +1,47 @@
|
|
|
-from datetime import datetime
|
|
|
-from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
|
-
|
|
|
+import HTTPServer, BaseHTTPRequestHandler
|
|
|
import requests
|
|
|
+import subprocess
|
|
|
+import datetime
|
|
|
|
|
|
-class HttpGethandler(BaseHTTPRequestHandler):
|
|
|
+class HttpGetHandler(BaseHTTPRequestHandler):
|
|
|
def do_GET(self):
|
|
|
try:
|
|
|
- if self.path.endswith("/"):
|
|
|
- self.send_response(200)
|
|
|
-
|
|
|
- self.send_header("Content-type", "text/html")
|
|
|
- self.end_headers()
|
|
|
-
|
|
|
- http_text = """<html><head><meta charset='utf-8'
|
|
|
- <title>Main</title></head>
|
|
|
- <body>Это Main.</body></html>"""
|
|
|
-
|
|
|
- self.wfile.write(http_text.encode())
|
|
|
-
|
|
|
- if self.path.endswith("/info"):
|
|
|
+ if self.path.endswith("/Status"):
|
|
|
self.send_response(200)
|
|
|
-
|
|
|
self.send_header("Content-type", "text/html")
|
|
|
self.end_headers()
|
|
|
-
|
|
|
- http_text = """<html><head><meta charset='utf-8'
|
|
|
- <title>Лаптев А.А 703</title></head></html>"""
|
|
|
-
|
|
|
- self.wfile.write(http_text.encode())
|
|
|
-
|
|
|
- if self.path.endswith("/status"):
|
|
|
- self.send_response(200)
|
|
|
-
|
|
|
- self.send_header("Content-type", "text/html")
|
|
|
- self.end_headers()
|
|
|
- get = requests.get(url='https://api.ipify.org/')
|
|
|
-
|
|
|
- http_text = f' <!doctype html><html><head><meta charset= utf-8><body>IP-адрес: {get.text}<br>Лаптев А.А 703<br>Время: {datetime.now()}</body></html>'
|
|
|
-
|
|
|
- self.wfile.write(http_text.encode())
|
|
|
- except eror:
|
|
|
- self.send_error(400, f"File not found{self.path}")
|
|
|
-
|
|
|
-def main(server_class=HTTPServer, handler_class=HttpGethandler):
|
|
|
+ get = requests.get('https://api.ipify.org/')
|
|
|
+ http_text = f"<html><head><meta charset = 'utf-8'>" \
|
|
|
+ f"<title>Main.</title></head>" \
|
|
|
+ f"<body>Your address {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>Answer</title></head>" \
|
|
|
+ f"<br>DNS Change" \
|
|
|
+ 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:
|
|
@@ -51,7 +50,7 @@ def main(server_class=HTTPServer, handler_class=HttpGethandler):
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
httpd.server_close()
|
|
|
- print("stop")
|
|
|
+ print("Stop")
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|