-
-
Save SamMousa/1f2cc2ca8ff9cbb095d6 to your computer and use it in GitHub Desktop.
Testing Draytek Vodaphone for Home Automation.
This file contains hidden or 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 re | |
import requests | |
from collections import namedtuple | |
import urllib | |
import base64 | |
# Change these to match your settings. I think the username/password | |
# is encoded, if it doesn't work, try changing `ENCODE_LOGIN` to False | |
# and see if it works better | |
USERNAME = 'admin' | |
PASSWORD = 'admin' | |
HOST = '10.0.2.252' | |
ENCODE_LOGIN = True | |
Device = namedtuple("Device", ["mac", "ip", "host"]) | |
def encode_login(ba): | |
if ENCODE_LOGIN: | |
return urllib.parse.quote_plus(base64.b64encode(str.encode(ba))) | |
else: | |
return ba | |
# Create our login/query URLS: | |
cookie_url = 'http://{host}/cgi-bin/wlogin.cgi?aa={username}&ab={password}'.format( | |
username=encode_login(USERNAME), | |
password=encode_login(PASSWORD), | |
host=HOST | |
) | |
query_url = 'http://{host}/doc/ipdhcptb.sht'.format(host=HOST) | |
# Make the requests for data: | |
session = requests.Session() | |
session.get(cookie_url) | |
results = session.get(query_url, allow_redirects=False).text | |
# Parse the results for device information: | |
# regex = r"##IP : ((?:[0-9]{1,3}\.){3}[0-9]{1,3})[ A-Z:]+?([\dA-F]{2}(?:[-:][\dA-F]{2}){5}) Comment : ([A-Z_0-9\-]+)" | |
regex = r"\'\d+\t((?:\d+\.?){4})\t((?:[\dA-F]+-?){6})\t(.*?)\t(.*?)\'" | |
parsed = re.findall(regex, results, re.MULTILINE|re.IGNORECASE) | |
devices = [Device(mac, ip, host[:-1].replace('_','-')) for ip, mac, host in parsed] | |
# Print it out to console: | |
if devices: | |
for device in devices: | |
print(device) | |
else: | |
# Nothing was found, but we didn't error out.. let's just | |
# spit out the HTML we got from the `query_url`: | |
print(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment