Last active
November 16, 2019 17:44
-
-
Save HassankSalim/5fc171d93cf6fa5bbca0e3394476db77 to your computer and use it in GitHub Desktop.
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 time | |
import json | |
import re | |
root_url = "http://192.168.0.1" | |
base_url = root_url + "/cgi" | |
login_url = base_url + "/login" | |
get_busy_url = base_url + "/getBusy" | |
stats_querystring = {"1":"","5":""} | |
stats_payload = b"[STAT_CFG#0,0,0,0,0,0#0,0,0,0,0,0]0,0\r\n[STAT_ENTRY#0,0,0,0,0,0#0,0,0,0,0,0]1,0\r\n" | |
login_querystring = {"UserName":"33d9646b3a579a3ed2ab6e7cdf19bdd84f7de70e5b0715b85ab539d27c924ca0d5d139c04896b68720e386db2da26b9621003cf0dc972e7f21b7f232d01d62322abe795d2ab518f8833f721da0a34c4c6bb2686eabca86d721618a","Passwd":"74287afbe4e50d9b16602c519088f6317f04e51aee132b43909408c4101aadontusethispassda82adfd7ee1ca5f1281bb8bf289d6c05718626cbf72a3bdd740d3ad1a530ce18dea889299996","Action":"1","LoginStatus":"0"} | |
login_headers = { | |
'Origin': "http://192.168.0.1", | |
'Accept-Encoding': "gzip, deflate", | |
'Accept-Language': "en-US,en;q=0.9", | |
'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36", | |
'Accept': "*/*", | |
'Referer': "http://192.168.0.1/", | |
'Connection': "keep-alive", | |
'Content-Length': "0", | |
'cache-control': "no-cache", | |
} | |
get_busy_headers = { | |
'Origin': "http://192.168.0.1", | |
'Accept-Encoding': "gzip, deflate", | |
'Accept-Language': "en-US,en;q=0.9", | |
'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36", | |
'Accept': "*/*", | |
'Referer': "http://192.168.0.1/", | |
'Connection': "keep-alive", | |
'Content-Length': "0", | |
'cache-control': "no-cache", | |
} | |
def get_token_id(cookie_id): | |
headers = { | |
'Connection': "keep-alive", | |
'Upgrade-Insecure-Requests': "1", | |
'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36", | |
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", | |
'Referer': "http://192.168.0.1/", | |
'Accept-Encoding': "gzip, deflate", | |
'Accept-Language': "en-US,en;q=0.9", | |
'Cookie': "JSESSIONID=" + cookie_id, | |
'cache-control': "no-cache", | |
} | |
response = requests.request("GET", root_url, headers=headers) | |
token_regex = r"token=\"([^\"]+)" | |
token_search = re.search(token_regex, response.text) | |
print(token_search.group()) | |
return token_search.group(1) | |
def clear_bus(cookie_id, token_id): | |
querystring = {"8":""} | |
payload = "[/cgi/clearBusy#0,0,0,0,0,0#0,0,0,0,0,0]0,0\\r\\n" | |
headers = { | |
'Origin': "http://192.168.0.1", | |
'Accept-Encoding': "gzip, deflate", | |
'Accept-Language': "en-US,en;q=0.9", | |
'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36", | |
'Content-Type': "text/plain", | |
'Accept': "*/*", | |
'Referer': "http://192.168.0.1/", | |
'Cookie': "JSESSIONID="+cookie_id, | |
'Connection': "keep-alive", | |
'TokenID': token_id, | |
'cache-control': "no-cache", | |
} | |
response = requests.request("POST", base_url, data=payload, headers=headers, params=querystring) | |
return { "success": True } | |
get_busy_response = requests.request("POST", get_busy_url, headers=get_busy_headers) | |
time.sleep(5) | |
login_response = requests.request("POST", login_url, headers=login_headers, params=login_querystring) | |
cookie_string = login_response.headers['Set-Cookie'] | |
cookie_id = cookie_string.split()[0][:-1].split('=')[-1] | |
token_id = get_token_id(cookie_id) | |
stats_headers = { | |
'Origin': "http://192.168.0.1", | |
'Accept-Encoding': "gzip, deflate", | |
'Accept-Language': "en-US,en;q=0.9", | |
'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36", | |
'Content-Type': "text/plain", | |
'Accept': "*/*", | |
'Referer': "http://192.168.0.1/", | |
'Cookie': "JSESSIONID=" + cookie_id, | |
'Connection': "keep-alive", | |
'TokenID': token_id, | |
'cache-control': "no-cache", | |
} | |
stats_response = requests.request("POST", base_url, data=stats_payload, headers=stats_headers, params=stats_querystring) | |
print(stats_response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment