-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_restart.py
41 lines (26 loc) · 1.02 KB
/
router_restart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from http.cookiejar import MozillaCookieJar
from bs4 import BeautifulSoup as soup
import requests
cookies = MozillaCookieJar()
url = '<URL>'
login_data = {
'username_login': '<USERNAME>',
'password_login': '<PASSWORD>',
'language_selector': 'en'
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
#Create login session and set cookie
with requests.Session() as session:
session.cookies = cookies
response = session.post(url+'/goform/logon', data=login_data, cookies=cookies)
print(cookies)
# Using a cookie, load the restart page to obtain token
restart_page = requests.get(url+'/ad_restart_gateway.html', cookies=cookies)
token = soup(restart_page.text, 'html.parser').select_one('input')['value']
token = "csrftoken="+token
# Send data to the ad_restart_gateway form using the token generated before
restart_data = token+"&tch_devicerestart=0x00"
restart = requests.post(url+'/goform/ad_restart_gateway', cookies=cookies, headers=headers, data=restart_data.encode())
print(restart.text)