12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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</h1>
- <p>General 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>Stalin Tyan</h1>
- <p>Slava Sovetskomu Souzu</p>
- <button onclick="location.href='/'">Back</button>
- <h2><img src="https://yt3.googleusercontent.com/ytc/AGIKgqODvXcSJJzpm-fzI3o42tAXsdA4AdX0j4EjuiNHlQE=s900-c-k-c0x00ffffff-no-rj"></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 = "Не найден :("
- 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()
|