浏览代码

Загрузить файлы ''

gr714_vidvl 4 月之前
父节点
当前提交
c05b04dbf5
共有 1 个文件被更改,包括 78 次插入0 次删除
  1. 78 0
      server-2.0(1).py

+ 78 - 0
server-2.0(1).py

@@ -0,0 +1,78 @@
+import http.server
+import socketserver
+import socket
+from datetime import datetime
+
+from ipaddress import ip_address
+import self
+from pip._internal.vcs import git
+
+class MyHandler(http.server.SimpleHTTPRequestHandler):
+    def do_GET(self):
+        if self.path == '/':
+            self.send_response(200)
+            self.send_header('Content-type', 'text/html; charset=utf-8')
+            self.end_headers()
+            self.wfile.write(b"""
+                <html>
+                <head><title>Fits Page</title></head>
+                <body>
+                    <h1>Hello world!</h1>
+                    <p>Main page</p>
+                    <button onclick="location.href='/status'">Status</button>
+                    <button onclick="location.href='/img'">img</button>
+                </body>
+                </html>
+            """)
+
+        elif self.path == '/img':
+            self.send_response(200)
+            self.send_header('Content-type', 'text/html; charset=utf-8')
+            self.end_headers()
+            self.wfile.write(b"""
+                <html>
+                <head><title>Image</title></head>
+                <body>
+                    <h1>Kotik</h1>
+                    <p>Valera</p>
+                    <button onclick="location.href='/'">Back</button>
+                    <h2><img src="https://sun9-5.userapi.com/impg/Wh22NP0d40s2qlcKFYV6-KdfGZjS5IfsCKrzEQ/z_j4vlD3lDs.jpg?size=512x512&quality=96&sign=479f6575d6e4a0f355f1f039c7564fa7&type=album"></h2>
+                </body>
+                </html>
+            """)
+
+
+        elif self.path == '/status':
+            ip_address = self.client_address[0]
+            ip_parts = ip_address[0].split('.')
+        if len(ip_parts) == 4:
+            masked_ip = f"{ip_parts[0]}.***.***.{ip_parts[3]}"
+
+        else:
+            masked_ip = "Not Found"
+            student_name = ("Виноградов_Дмитрий_Владимирович_714_группа")
+            current_time = datetime.now().strftime("%d.%m.%Y %I:%M:%S %p")
+
+            response_content = f"""
+                <html>
+                <head><title>Status Page</title></head>
+                <body>
+                    <h1>Статус:</h1>
+                    <p>Ip-адрес: {masked_ip}</p>
+                    <p>Фио: {student_name}</p>
+                    <p>Текущее время: {current_time}</p>
+                    <button onclick="location.href='/'">Back</button>
+                </body>
+                </html>
+            """.encode("utf-8")
+            self.send_response(200)
+            self.send_header('Content-type', 'text/html; charset=utf-8')
+            self.end_headers()
+            self.wfile.write(response_content)
+
+hostname = socket.gethostname()
+port = 8080
+
+with socketserver.TCPServer((hostname, port), MyHandler) as httpd:
+    print(f"Server on {hostname}:{port}")
+    httpd.serve_forever()