first commit

This commit is contained in:
Maxim Slipenko 2023-09-04 23:43:45 +03:00
commit ff38bc6c47
8 changed files with 102 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,14 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N802" />
<option value="N803" />
<option value="N806" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 2.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/keenetic-dpr-bypass.iml" filepath="$PROJECT_DIR$/.idea/keenetic-dpr-bypass.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

51
main.py Normal file
View File

@ -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()