I need to log into the router using python and http method due to the fact that i can't use telnet or SSH with it. is it possible ? i looked and found different approaches but all just lead to errors or just fetch html page of the login page and doesn't log into the router. if anyone can explain to me how to do it, i will appreciate that.
also if the ip used with https not http, how to bypass the Warning Page (which requires to press a button in order to enter a router) ?.
below is the codes i tried :
import requests
url = 'http://your-router-ip/login'
payload = {
'username': 'your_username',
'password': 'your_password'
}
response = requests.post(url, data=payload)
# Check if login was successful
if response.status_code == 200:
print("Login successful")
else:
print("Login failed")
another approach
from bs4 import BeautifulSoup
import requests
with requests.session() as session:
page = session.get('http://192.168.0.1')
html = BeautifulSoup(page.content,'html.parser')
print(html)
csrf_token = html.find('input',{'name':'csrf_token'})['value']
data_to_login = {'username':'admin','password':'admin', 'csrf_token': csrf_token}
t = session.post('http://192.168.0.1',data_to_login)
print(t.text)