123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 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"<!doctype html><html><head><meta charset=utf-8><title>HTTP server</title></head><body>" \
- f"IP Address: {ipv4_ip}<br>" \
- f"Mask: {ipv4_mask}<br>" \
- f"Default gateway: {ipv4_gateway}<br>" \
- f"DNS1: {ipv4_dns_1}<br>" \
- f"DNS2: {ipv4_dns_2}<br>" \
- f"</body></html>"
- 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()
|