123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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()
|