commit ff38bc6c47130f9da49c723b2cce08e87cbc4e00 Author: Maxim Slipenko Date: Mon Sep 4 23:43:45 2023 +0300 first commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..e96f6e0 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/keenetic-dpr-bypass.iml b/.idea/keenetic-dpr-bypass.iml new file mode 100644 index 0000000..9455a52 --- /dev/null +++ b/.idea/keenetic-dpr-bypass.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7ba73c2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3885051 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..3ecef02 --- /dev/null +++ b/main.py @@ -0,0 +1,51 @@ +import httplib +import hashlib +import json + + +class KeeneticAPI: + def __init__(self, destination="192.168.1.1"): + self._conn = httplib.HTTPConnection(destination) + self._cookie = "" + pass + + def _get(self, url): + headers = {"Cookie": self._cookie} + self._conn.request("GET", url, "", headers) + res = self._conn.getresponse() + data = res.read() + return res, data + + def _post(self, url, body): + headers = {"Content-type": "application/json", "Cookie": self._cookie} + self._conn.request("POST", url, body, headers) + res = self._conn.getresponse() + data = res.read() + return res, data + + def auth(self, login, passw): + res, _ = self._get("/auth") + self._cookie = res.getheader("Set-Cookie") + + if res.status == 401: + md5 = login + ":" + res.getheader("X-NDM-Realm") + ":" + passw + md5 = hashlib.md5(md5.encode('utf-8')) + sha = res.getheader("X-NDM-Challenge") + md5.hexdigest() + sha = hashlib.sha256(sha.encode('utf-8')) + + self._post("/auth", json.dumps({"login": login, "password": sha.hexdigest()})) + + def show_ip_route(self): + res, data = self._get("/rci/show/ip/route") + print data + + +def main(): + api = KeeneticAPI() + api.auth("test", "test") + api.show_ip_route() + + + +if __name__ == "__main__": + main()