Skip to content

Instantly share code, notes, and snippets.

@aziz0x00
Last active July 20, 2024 00:34
Show Gist options
  • Save aziz0x00/5c1efc9cd5ef688b366b4076f37f32b9 to your computer and use it in GitHub Desktop.
Save aziz0x00/5c1efc9cd5ef688b366b4076f37f32b9 to your computer and use it in GitHub Desktop.
A script to list wifi devices instead of the slow annoying panel
import re, base64
import requests
# this is tested on HG8145V5,
# NOTE: there's a default telecomadmin:admintelecom auth which is stronger than root.
# ofc don't use it without permission
# change it on your device to not let anyone connected control your router.
USERNAME = "root"
PASSWORD = "????" # MODIFY THIS
sess = requests.Session()
sess.headers["Content-Type"] = "application/x-www-form-urlencoded"
# sess.proxies = {"http": "http://localhost:8080"}
X_HW_Token = ""
def auth():
global X_HW_Token
resp = sess.post("http://192.168.100.1/asp/GetRandCount.asp")
# print(resp.text)
X_HW_Token = resp.content[3:].decode()
# print(X_HW_Token)
epwd = base64.b64encode(PASSWORD.encode()).decode()
resp = sess.post(
"http://192.168.100.1/login.cgi",
data=f"UserName={USERNAME}&PassWord={epwd}&Language=english&x.X_HW_Token={X_HW_Token}",
)
assert "index.asp" in resp.text, "Login failed"
# print(resp.content)
def show_list():
import ast
def parse(s):
s = re.sub(r"[^=]*= new Array", "", s)
s = re.sub(r",null\);$", "", s)
s = s.replace("USERDevice(", "[").replace("),new ", "],")
s = re.sub(r"^\(new ", "", s)[:-1] + "]"
return ast.literal_eval(s)
resp = sess.post("http://192.168.100.1/html/bbsp/common/GetLanUserDevInfo.asp")
data = [i for i in resp.text.splitlines() if "Online" in i][-1]
data = parse(data)
wlist = [[i[9], i[6], i[3], i[8]] + i[1:3] + [i[5]] for i in data]
wlist.sort(key=lambda d: d[2])
wlist.sort(key=lambda d: d[1] == "Online")
from rich.console import Console
from rich.table import Table, box
table = Table()
table.add_column("Hostname", style="cyan", no_wrap=True)
table.add_column("Status", justify="right")
table.add_column("PortID", justify="right")
table.add_column("Time?", justify="right")
table.add_column("IP", style="magenta", no_wrap=True)
table.add_column("MAC", justify="left")
table.add_column("DHCP client", justify="right")
table.border_style = "bright_yellow"
table.box = box.SIMPLE_HEAD
for dev in wlist:
style = None
dev[1] = dev[1].upper()
if dev[1] == "ONLINE":
dev[1] = "[green]ONLINE[/green]"
if dev[2] != "SSID1":
dev[1] = "[red]ONLINE[/red]"
else:
style = "dim"
table.add_row(*dev, style=style)
Console().print(table)
if __name__ == "__main__":
auth()
show_list()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment