gr701_kinvya пре 2 година
родитељ
комит
ba97787978
1 измењених фајлова са 31 додато и 9 уклоњено
  1. 31 9
      Code.py

+ 31 - 9
Code.py

@@ -1,5 +1,6 @@
-
 from http.server import HTTPServer, BaseHTTPRequestHandler
+from datetime import datetime
+import re
 
 class HttpGetHandler(BaseHTTPRequestHandler):
     def do_GET(self):
@@ -10,10 +11,11 @@ class HttpGetHandler(BaseHTTPRequestHandler):
                 self.send_header("Content-type", "text/html")
                 self.end_headers()
 
-                http_text = """<html><head><meta charset='utf-8'>
+                http_text = """<html><head><meta charset="utf-8">
                                 <title>Simple HTTP Server</title></head>
-                                <body>Типа главная страница<br>
-                                <a href="http://localhost:8000/info">Info</a></body><html>"""
+                                <body>Главная страница<br><br>
+                                <a href="http://localhost:8000/info">Info</a><br>
+                                <a href="http://localhost:8000/status">Статус</a></body><html>"""
                
                 self.wfile.write(http_text.encode())
             if self.path.endswith("/info"):
@@ -22,13 +24,31 @@ class HttpGetHandler(BaseHTTPRequestHandler):
                 self.send_header("Content-type", "text/html")
                 self.end_headers()
 
-                http_text = """<html><head><meta charset='utf-8'>
-                                <title>Емае</title></head>
-                                <body>Кипиченков Никита Вячеславович 701(3)<br>
-                                <a href="http://localhost:8000/">На главную</a></body><html>"""
+                http_text = """<html><head><meta charset="utf-8">
+                                <title>Info</title></head>
+                                <body>Кипиченков Никита Вячеславович 701(3)<br><br>
+                                <a href="http://localhost:8000/">На главную</a><br>
+                                <a href="http://localhost:8000/status">Статус</a></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"<a href='http://localhost:8000/'>На главную</a><br>" \
+                            f"<a href='http://localhost:8000/info'>Info</a></body></html>"
+                self.wfile.write(http_text.encode())
         except IOError:
             self.send_error(400,f"File not found{self.path}")
 
@@ -43,5 +63,7 @@ def main(server_class=HTTPServer,handler_class=HttpGetHandler):
         httpd.server_close()
         print("Killing the Server!")
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     main()
+    
+