Created
February 1, 2018 14:18
-
-
Save initialed85/abae063f04c819c867255f804cb0709f to your computer and use it in GitHub Desktop.
Example interaction with Ubiquiti AirOS "API"
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
# Requirements: | |
# | |
# Python 2.7 | |
# Requests package (pip install requests) | |
import pprint | |
import requests | |
from requests.packages.urllib3.exceptions import InsecureRequestWarning | |
USERNAME = 'some_readonly_username' | |
PASSWORD = 'some_readonly_password' | |
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) | |
login_url = 'https://{0}/api/auth' | |
urls = [ | |
'http://{0}/arp.cgi', | |
'http://{0}/brmacs.cgi?brmacs=y', | |
'http://{0}/sroutes.cgi', | |
'http://{0}/status.cgi', | |
# the following don't seem to work on AirOS 8 | |
'http://{0}/getcfg.sh', | |
'http://{0}/getboardinfo.sh', | |
'http://{0}/sta.cgi', | |
'http://{0}/ifstats.cgi', | |
'http://{0}/iflist.cgi', | |
'http://{0}/log.cgi', | |
] | |
ips = [ | |
'1.2.3.4', | |
'5.6.7.8', | |
] | |
responses_by_ip = {} | |
for ip in ips: | |
# keep a session | |
with requests.Session() as s: | |
# conduct the login | |
r = s.post( | |
url=login_url.format(ip), | |
data={ | |
'username': USERNAME, | |
'password': PASSWORD, | |
}, | |
verify=False, | |
timeout=5, | |
) | |
# skip this IP if the login fails | |
if r.status_code > 201: | |
continue | |
responses = {} | |
# scrape the URLs | |
for url in urls: | |
url = url.format(ip) | |
r = s.get( | |
url=url, | |
verify=False | |
) | |
responses.update({url: r.json() if r.status_code == 200 else r.status_code}) | |
responses_by_ip.update({ip: responses}) | |
pprint.pprint(responses_by_ip) |
@Mohmmed66mazen you're welcome! This is pretty old code though- it still works? They haven't changed their firmware much?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks man 🤝