Ich möchte die Daten von meinem Router für einige Hausautomation verschrotten, aber ich bin mit einigen Problemen konfrontiert, die ich nicht lösen kann/knacken kann.Autorisierungsfehler beim Parsen von Daten vom Router
Ich habe es geschafft, erfolgreich in den Router einzuloggen, aber beim Zugriff auf die Daten mit Python-Skript (Öffnen von Links in Router-Web-Interface) erhalte ich eine Fehlermeldung: Sie haben keine Berechtigung, auf diesen Router zuzugreifen!
Wenn ich URL manuell kopieren und einfügen, dass Python-Skript in Browser (mit Cookies gesetzt) greift, ist die Antwort identisch. Aber wenn ich auf die Buttons innerhalb des Router-Web-Interface klicke, bekomme ich keine "Berechtigung". Irgendwelche Ideen, wie das zu beheben ist?
hier ist das Skript:
import re
import mechanize
import cookielib
br = mechanize.Browser()
cookies = cookielib.LWPCookieJar()
br.set_cookiejar(cookies)
#they "encrypt" the username and password and store it into the cookie. I stole this value from javascript in runtime.
br.addheaders = [('Cookie','Authorization=Basic YWRtaW46MjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzM=;')]
#open connection to the router address
br.open('http://192.168.1.1/')
#the only form is "login" form (which we dont have to fill up, because we already have the cookie)
br.select_form(nr=0)
br.form.enctype = "application/x-www-form-urlencoded"
br.submit()
#then the router returns redirect script, so we have to parse it (get the url).
redirect_url = re.search('(http:\/\/[^"]+)',br.response().read()).group(1)
token = re.search("1\/([A-Z]+)\/",redirect_url).group(1) #url always has a random token inside (some kind of security?)
#So with this url I should be able to navigate to page containing list of DHCP clients
br.open("http://192.168.1.1/"+token+"/userRpm/AssignedIpAddrListRpm.htm")
print(br.response().read()) #But response contains html saying "You have no authority to access this router!".