|
@@ -1,8 +1,10 @@
|
|
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
|
+from datetime import datetime
|
|
|
+import re
|
|
|
class HttpGetHandler(BaseHTTPRequestHandler):
|
|
|
def do_GET(self):
|
|
|
try:
|
|
|
- if self.path.endswith("/OK"):
|
|
|
+ if self.path.endswith("/"):
|
|
|
self.send_response(200)
|
|
|
self.send_header("Content-type", "text/html")
|
|
|
self.end_headers()
|
|
@@ -18,9 +20,28 @@ class HttpGetHandler(BaseHTTPRequestHandler):
|
|
|
<title> Простой HTTP-сервер.</title></head>
|
|
|
<body>Группа 701 Жучков Алексей Витальевич.</body></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()
|
|
|
+
|
|
|
+ dt = datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
|
|
|
+ _ip = self.client_address[0]
|
|
|
+ _ip = re.sub("([.][0-9]{1,3})", ".x", _ip, count = 2)
|
|
|
+
|
|
|
+ http_text = f"<html><head><meta charset='utf-8'>" \
|
|
|
+ f"<title>Status</title></head>" \
|
|
|
+ f"<body>Ваш IP:{_ip}<br>" \
|
|
|
+ f"ФИО: Жучков Алексей Витальевич<br>" \
|
|
|
+ f"Дата: {dt}<br><br>" \
|
|
|
+ f"</body></html>"
|
|
|
+ self.wfile.write(http_text.encode())
|
|
|
+
|
|
|
except IOError:
|
|
|
self.send_error(400,f"File not found{self.path}")
|
|
|
|
|
|
+
|
|
|
def main(server_class=HTTPServer,handler_class=HttpGetHandler):
|
|
|
server_address = ('localhost', 8000)
|
|
|
httpd = server_class(server_address, handler_class)
|