Adam 2 роки тому
батько
коміт
6e6281ae10
1 змінених файлів з 41 додано та 5 видалено
  1. 41 5
      ifcfg.py

+ 41 - 5
ifcfg.py

@@ -1,9 +1,45 @@
+from http.server import HTTPServer, BaseHTTPRequestHandler
 import subprocess
 
-n = 1
 config = subprocess.check_output(
     ['chcp', '65001', '&', 'netsh', 'interface', 'ipv4', 'show', 'config'], shell=True)
-while n != 10:
-    check = config.decode('utf-8').split('Configuration for interface "Беспроводная сеть"')[1].split('\n')[n]
-    print(check)
-    n += 1
+mask = config.decode("utf-8").split('Ethernet')[1].split("\n")[3].split(":")[1].split(":")[0]
+ip = config.decode("utf-8").split('Ethernet')[1].split("\n")[2].split(":")[1]
+dns1 = config.decode("utf-8").split('Ethernet')[1].split("\n")[7].split(":")[1]
+dns2 = config.decode("utf-8").split('Ethernet')[1].split("\n")[8].split(":")[0]
+gateway = config.decode("utf-8").split('Ethernet')[1].split("\n")[4].split(":")[1]
+
+class HttpGethandler(BaseHTTPRequestHandler):
+    def do_GET(self):
+        try:
+            if self.path.endswith("/status"):
+                self.send_response(200)
+                self.send_header("Content-type", "text/html")
+                self.end_headers()
+                html = " "
+                html += mask
+                html += ip
+                html += dns1
+                html += dns2
+                html += gateway
+                html = f"<html><head><meta charset='utf-8'><title>Damned HTTP-Server</title></head>" \
+                       f"<body>IP - {ip}<br>Mask - {mask}<br>Gateway - {gateway}<br>DNS 1 - {dns1}<br>DNS 2 - {dns2}</body>"
+                self.wfile.write(html.encode())
+        except IOError:
+            self.send_error(400, f'Damned HTTP-Server not found{self.path}')
+
+
+def main(server_class=HTTPServer, handler_class=HttpGethandler):
+    server_address = ('localhost', 8000)
+    httpd = server_class(server_address, handler_class)
+    try:
+        print("Damned HTTP-Server started")
+        httpd.serve_forever()
+
+    except KeyboardInterrupt:
+        httpd.server_close()
+        print("Damned HTTP-Server stopped")
+
+
+if __name__ == '__main__':
+    main()