Last active
January 21, 2024 18:41
-
-
Save fusion44/36abbccbdbba45681408da8d5da6b154 to your computer and use it in GitHub Desktop.
Login to FritzBox using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib3 | |
import xml.etree.ElementTree as ET | |
import hashlib | |
from requests import Session | |
username = "xxx" | |
fritz_pw = "xxx" | |
def get_md5_hash(challenge, password): | |
hash_me = (challenge + "-" + password).encode("UTF-16LE") | |
hashed = hashlib.md5(hash_me).hexdigest() | |
return challenge + "-" + hashed | |
def get_session_id(): | |
session = Session() | |
http = urllib3.PoolManager() | |
data = http.request("get", "http://fritz.box/login_sid.lua").data | |
tree = ET.fromstring(data) | |
sid = tree.findtext("SID") | |
if(sid == "0000000000000000"): | |
challenge = tree.findtext("Challenge") | |
ret = session.get("http://fritz.box/login_sid.lua", params={ | |
"username": username, | |
"response": get_md5_hash(challenge, fritz_pw) | |
}) | |
tree = ET.fromstring(ret.text) | |
sid = tree.findtext("SID") | |
if(sid == "0000000000000000"): | |
print("Error getting SID") | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you wanted to return the sid not the data in the last line:
return sid
instead of
return data