|
@@ -1,6 +1,7 @@
|
|
|
from http.server \
|
|
|
import HTTPServer, BaseHTTPRequestHandler
|
|
|
import requests
|
|
|
+import subprocess
|
|
|
import datetime
|
|
|
|
|
|
class HttpGetHandler(BaseHTTPRequestHandler):
|
|
@@ -8,31 +9,37 @@ class HttpGetHandler(BaseHTTPRequestHandler):
|
|
|
try:
|
|
|
if self.path.endswith("/Status"):
|
|
|
self.send_response(200)
|
|
|
- self.send_header("Content-type","text/html")
|
|
|
+ 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> Моллаев Омар Рашидович 701(3) группа <br>" \
|
|
|
- f"Время на сервере {str(datetime.datetime.now())}" \
|
|
|
+ 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())
|
|
|
-
|
|
|
-
|
|
|
- if self.path.endswith("/info"):
|
|
|
- self.send_response(200)
|
|
|
- self.send_header("Content-type", "text/html")
|
|
|
- self.end_headers()
|
|
|
-
|
|
|
- html = """ <html><head><meta charset = 'utf-8'>
|
|
|
- <title>Простой HTTP-сервер.</title></head>
|
|
|
- <body>Моллаев Омар Рашидович,студент 701(3) группы.</body></html> """
|
|
|
|
|
|
- self.wfile.write(html.encode())
|
|
|
+ self.wfile.write(http_text.encode('utf-8'))
|
|
|
|
|
|
except IOError:
|
|
|
- self.send_error(400,"File not found{self.path}")
|
|
|
+ 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):
|