main.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from http.server import HTTPServer, BaseHTTPRequestHandler
  2. import subprocess
  3. config = subprocess.check_output(
  4. ['chcp', '65001', '&', 'netsh', 'interface', 'ipv4', 'show', 'config'], shell=True)
  5. mask = config.decode("utf-8").split('Ethernet')[1].split("\n")[3].split(":")[1].split(":")[0]
  6. ip = config.decode("utf-8").split('Ethernet')[1].split("\n")[2].split(":")[1]
  7. dns1 = config.decode("utf-8").split('Ethernet')[1].split("\n")[7].split(":")[1]
  8. dns2 = config.decode("utf-8").split('Ethernet')[1].split("\n")[8].split(":")[0]
  9. gateway = config.decode("utf-8").split('Ethernet')[1].split("\n")[4].split(":")[1]
  10. class HttpGethandler(BaseHTTPRequestHandler):
  11. def do_GET(self):
  12. try:
  13. if self.path.endswith("/status"):
  14. self.send_response(200)
  15. self.send_header("Content-type", "text/html")
  16. self.end_headers()
  17. html = " "
  18. html += mask
  19. html += ip
  20. html += dns1
  21. html += dns2
  22. html += gateway
  23. html = f"<html><head><meta charset='utf-8'><title>HTTP-Server</title></head>" \
  24. f"<body>IP - {ip}<br>Mask - {mask}<br>Gateway - {gateway}<br>DNS 1 - {dns1}<br>DNS 2 - {dns2}</body>"
  25. self.wfile.write(html.encode())
  26. except IOError:
  27. self.send_error(400, f'Да кто блин этот ваш сервер{self.path}')
  28. def main(server_class=HTTPServer, handler_class=HttpGethandler):
  29. server_address = ('localhost', 8000)
  30. httpd = server_class(server_address, handler_class)
  31. try:
  32. print("Сервер встал")
  33. httpd.serve_forever()
  34. except KeyboardInterrupt:
  35. httpd.server_close()
  36. print("Сервер упал")
  37. if __name__ == '__main__':
  38. main()