Retrieving statistics from a TP-Link TL-WA801ND WAP

I recently upgraded my home wireless network via a dedicated WAP as the one built-in to my router struggled with coverage. In doing so I lost the ability to retrieve statistics like the number of connected wireless clients as it doesn’t support SNMP.

I thought it would be relatively easy to scrape this information from the web interface, but no. Although I found the page that contained this it seems you have to fetch a couple of other pages before it will serve it up.

So, in case anyone may be interested in doing this here is a simply Python script that displays the number of connected wireless clients in a format suitable for graphing with MRTG.


#!/usr/bin/env python3
import re
from urllib.parse import urljoin
import requests
from bs4 import BeautifulSoup

BASE_URL = 'http://192.168.128.254/'
headers = {'Referer': BASE_URL}
auth = ('admin', 'yourpasswordgoeshere')
s = requests.Session()
r = s.get(BASE_URL, headers=headers, auth=auth)
r = s.get(BASE_URL + 'dynaform/css_main.css', headers=headers, auth=auth)
r = s.get(BASE_URL + 'dynaform/common.js', headers=headers, auth=auth)
r = s.get(BASE_URL + 'localiztion/char_set.js', headers=headers, auth=auth)
r = s.get(BASE_URL + 'userRpm/WlanStationRpm.htm', headers=headers, auth=auth)
soup = BeautifulSoup(r.text)
js = soup.find('script')
jss = str(js).replace('\n','')
m = re.search('Array\((\d+)',jss)
if m:
print(m.group(1))
print('0\n0\nWireless Clients')

Leave a Reply