Skip to content

Instantly share code, notes, and snippets.

@fusion44
Last active January 21, 2024 18:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fusion44/36abbccbdbba45681408da8d5da6b154 to your computer and use it in GitHub Desktop.
Save fusion44/36abbccbdbba45681408da8d5da6b154 to your computer and use it in GitHub Desktop.
Login to FritzBox using Python
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
@kbudde
Copy link

kbudde commented Aug 10, 2021

I think you wanted to return the sid not the data in the last line:

return sid
instead of
return data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment