import subprocess from http.server import BaseHTTPRequestHandler, HTTPServer serverPort = 8000 config = subprocess.check_output( ['chcp', '65001', '&', 'netsh', 'interface', 'ipv4', 'show', 'config'], shell=True) ipv4_ip = \ config.decode('utf-8').split('Configuration for interface "Ethernet"')[1].split('\n')[2].split(' ')[-1] ipv4_mask = \ config.decode('utf-8').split('Configuration for interface "Ethernet"')[1].split('\n')[3].split(' ')[-1][:-1][:-1] ipv4_gateway = \ config.decode('utf-8').split('Configuration for interface "Ethernet"')[1].split('\n')[4].split(' ')[-1] ipv4_dns_1 = \ config.decode('utf-8').split('Configuration for interface "Ethernet"')[1].split('\n')[7].split(' ')[-1] ipv4_dns_2 = \ config.decode('utf-8').split('Configuration for interface "Ethernet"')[1].split('\n')[8].split(' ')[-1] class HttpGetHandler(BaseHTTPRequestHandler): def do_GET(self): if self.path.endswith("/"): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() html = f"HTTP server" \ f"IP Address: {ipv4_ip}
" \ f"Mask: {ipv4_mask}
" \ f"Default gateway: {ipv4_gateway}
" \ f"DNS1: {ipv4_dns_1}
" \ f"DNS2: {ipv4_dns_2}
" \ f"" self.wfile.write(html.encode('utf-8')) def main(server_class=HTTPServer, handler_class=HttpGetHandler): server_address = ('localhost', 8000) httpd = server_class(server_address, handler_class) try: print("Server run...") httpd.serve_forever() except KeyboardInterrupt: httpd.server_close() print("Stopped.") if __name__ == '__main__': main()