Created
March 22, 2016 18:55
-
-
Save klattimer/461dc46771920fdf025f to your computer and use it in GitHub Desktop.
I wrote this because I wanted to get the JSON data from OpenWRT's status page and use it elsewhere. Fill out the user name and password, sorry it's a bit hacky but I'm rolling it into other stuff and this is a minimum implementation.
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 requests | |
import re | |
import urllib2 | |
url = 'http://openwrt/cgi-bin/luci/' | |
data = {'luci_username': 'root', 'luci_password': 'password'} | |
r = requests.post(url, data=data, allow_redirects=True) | |
cookie = r.request.headers['Cookie'] | |
m = re.search('sysauth=(.*)', cookie, re.IGNORECASE) | |
sysauth = m.group(1) | |
m = re.search('stok=(.*?)/', r.content, re.IGNORECASE) | |
stok = m.group(1) | |
statusurl = url+';stok=' + stok + '?status=1&_=0.0121' | |
r = urllib2.Request(statusurl) | |
r.add_header('Cookie', 'sysauth='+sysauth) | |
resp = urllib2.urlopen(r) | |
print resp.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment