Getting data from the Plusnet router
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- Re: Getting data from the Plusnet router
Getting data from the Plusnet router
05-04-2022 4:05 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
The router PlusNet shipped to me is the basic Plusnet Hub One that does not seem to support SNMP or Telnet for management or reporting. It does however have a simple summary screen designed for 'Helpdesk Agents' that has most of the core information on it that can be accessed via a 'scrape' if you can get past the security on the page.
Fortunately, two kind folk have made this method public (they used it to get the external IP address) - the first is Gebbl of Bits and Bobs and the subsequent fork from eharrow on Github correcting some Bash scripting from an early post of Gebbl.
I have removed the IP search and added a few lines to access the reporting screen and convert the data to a Python dictionary for later processing. Note though, this stub of a program only prints the extracted data - I'll leave it up to you to decide what to do about reporting.
The script pulls most information out of the page EXCEPT for the uptime of the DSL link - I've not yet worked out how to run the calculation so if you have any ideas please chip in!
This script runs on a Raspberry Pi 4 running Bullseye fine - it may run on other Linux versions but I've not tested it - it assumes that the python command is v3 and you have BeautifulSoup installed.
I do know it does not run as it stands on an Intel Mac under Catalina 10.15.7 (and I've not tried to sort why but think it is the password hash function via openssl as the hash is empty).
As I have no need for the IP address those lines have been removed. You could pass the IP address to Python if you need it by re-inserting line 19 of the GITHUB code, adding an export command and pulling it in via os.environ["IP"] in the Python program.
The script creates and destroys a file cookies.txt in the current directory when run.
The first part is a Bash script that takes the IP address and your router password as parameters (use quotes and / or '\' if you have spaces etc in your password):
#!/bin/bash
# Screen scrape the Plusnet Hub's admin screens to get the router summary screen (Troubleshooting / Helpdesk)
# Forked from https://raw.githubusercontent.com/eharrow/plusnet-hub/master/whatsmyip.sh and
# https://www.gebbl.net/2017/01/the-plusnet-hub-one-and-webscraping-for-fun-and-profit/
router=$1
pass=$2
page=$(curl -Ls "http://$router/index.cgi?active_page=9148" -H 'Cookie: rg_cookie_session_id=' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'DNT: 1' --data 'active_page=9121' --cookie-jar cookies.txt)
posttoken=$(echo $page |grep post_token |awk 'BEGIN { FS = "\"post_token\" value=\"" } ; {print $2}'|awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
requestid=$(echo $page |grep request_id |awk 'BEGIN { FS = "\"request_id\" value=\"" } ; {print $2}'|awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
authkey=$(echo $page |grep auth_key |awk 'BEGIN { FS = "\"auth_key\" value=\"" } ; {print $2}'|awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
passwordid=$(echo $page |grep password_ |awk 'BEGIN { FS = "\"password_" } ; {print $2}'| awk 'BEGIN { FS = "\"" } ; {print $1}'|xargs)
pass+=$authkey
passhash=$(echo -n $pass |openssl dgst -md5|awk '{print $2}')
postvars="request_id=$requestid&active_page=9148&active_page_str=bt_login&mimic_button_field=submit_button_login_submit%3A+..&button_value=&post_token=$posttoken&password_$passwordid=&md5_pass=$passhash&auth_key=$authkey"
curl -Ls "http://$router/index.cgi" -H 'Content-Type: application/x-www-form-urlencoded' -H 'Cache-Control: max-age=0' -H 'Referer: http://$router/index.cgi?active_page=9121' -H 'Connection: keep-alive' -H 'DNT: 1' --data "$postvars" --cookie cookies.txt >/dev/null
hdesk=$(curl -s "http://$router/index.cgi?active_page=9143&nav_clear=1" -H 'DNT: 1' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --cookie cookies.txt --compressed)
export hdesk
python procrtr.py
# Tidy up
hdesk=""
rm -r cookies.txt
The second part is the Python 3.x program that extracts the data into a dictionary keyed by the item number reported where the data is the description and value from the row:
import os
import pprint # Only needed for tidy printing
from bs4 import BeautifulSoup
rtrData = {}
RawSoup = BeautifulSoup(os.environ["hdesk"], "html.parser")
# The sixth table contains the router data / configuration report but has the intro text and a blank row that must be skipped
# Hence the for loop starts at row 2 onwards
DataTable = RawSoup.body.find_all('table')[6]
# Data format is <number>.<description>:<value>
# Each data element on its own row
# Elements 6-11 inc. have spaces between the '/' seperator that are removed
for rptRow in DataTable.find_all('tr')[2:]:
DataLine = rptRow.text
rptIndex = int(DataLine.split('.')[0])
rptDesc = DataLine.split(':')[0].split('.',1)[1].strip()
rptValue = DataLine.split(':',1)[1]
if rptIndex in range(6, 12):
rptValue = rptValue.split('/')[0].strip() + '/' + rptValue.split('/')[1].strip()
rtrData[rptIndex] = [rptDesc, rptValue]
pprint.pprint(rtrData)
To execute, make the script executable (chmod +x ./readrtr.sh) then call:
./readrtr.sh 192.168.1.254 routeradminpassword
Running the script should give you output along the lines of:
{1: ['Product name', 'Plusnet Hub'],
2: ['Serial number', 'redacted'],
3: ['Firmware version',
'Software version 4.7.5.1.83.8.289.1.3 Last updated 20/03/22'],
4: ['Board version', 'Plusnet Hub One'],
5: ['DSL uptime', ' '],
6: ['Data rate', '9999/39950'],
7: ['Maximum data rate', '10439/57661'],
8: ['Noise margin', '6.8/14.5'],
9: ['Line attenuation', '33.6/21.4'],
10: ['Signal attenuation', '33.4/20.0'],
11: ['Data sent/received', '12.0 GB/299.0 GB'],
12: ['Broadband username', 'redacted'],
13: ['2.4 GHz Wireless network/SSID', 'redacted'],
14: ['2.4 GHz Wireless connections', 'Disabled'],
15: ['2.4 GHz Wireless security', 'WPA2'],
16: ['2.4 GHz Wireless channel', 'Automatic (Smart Wireless)'],
17: ['5 GHz Wireless network/SSID', 'redacted'],
18: ['5 GHz Wireless connections', 'Disabled'],
19: ['5 GHz Wireless security', 'WPA2'],
20: ['5 GHz Wireless channel', 'Automatic (Smart Wireless)'],
21: ['Firewall', 'Default'],
22: ['MAC Address', 'redacted - though not really bothered'],
23: ['Modulation', 'G.993.2 Annex B'],
24: ['Software variant', 'AA'],
25: ['Boot loader', '1.0.0']}
Caveats:
It has been tested on ONE hub running one version of the software (see above - item 3).
It maybe fragile as ANY changes to the page layout or security could break the scrape.
As you have zero control (grrrr) over updates on these boxes it may just stop working.
I have not tested the output with the WiFi enabled - I have separate access points that handle the wifi connections.
I have not tested the output with the firewall set to anything but default - I'm not talking about security on my connection.
The MAC address is lowercase rather than the more normal upper case characters.
Using cookies.txt is not a good idea - it would be better to have a unique name for this file (possibly in tmpfs)
I have zero plans to support this and it may break your router / system / agreement with PlusNet.
This software is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Re: Getting data from the Plusnet router
05-04-2022 4:21 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Why go to that trouble - it is all available direct from the Hub interface?
Re: Getting data from the Plusnet router
05-04-2022 4:25 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
But if you wanted to do that, I'd jus buy a better router.
If it helped click the thumb
If it fixed it click 'This fixed my problem'
Re: Getting data from the Plusnet router
05-04-2022 4:28 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Get you, @dvorak , but how many people really need to do that? I'm a bit of a 'data freak' - not using either, but a FritzBox 7530 and wouldn't be that interested.
Re: Getting data from the Plusnet router
05-04-2022 4:30 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
@dvorak wrote:
Dump results every X minutes / hour you can plot performance. Reporting etc.
But if you wanted to do that, I'd jus buy a better router.
I have a choice - buy a router or pay the electric / food bills.
I also have asked for a recommendation for a 'real router' (work provided a Draytek set-up but I am no longer working so that's gone) but funding may be difficult unless eBay comes up with something that matches.
Re: Getting data from the Plusnet router
05-04-2022 4:32 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: Getting data from the Plusnet router
05-04-2022 4:33 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
If OR said that to me, I'd be somewhat suspicious, to be truthful.
Re: Getting data from the Plusnet router
05-04-2022 4:48 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Suspicious? You're not suggesting that an Openreach 'engineer' would say something like that just to get off site?
Moderator and Customer
If this helped - select the Thumb
If it fixed it, help others - select 'This Fixed My Problem'
Re: Getting data from the Plusnet router
05-04-2022 4:50 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Of course not, @Baldrick1 - they'd never do anything as underhand as that, would they?🤣
Re: Getting data from the Plusnet router
02-05-2022 4:13 PM - edited 02-05-2022 4:19 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
A bit late to the party - but if you want to know what is going on with your Plusnet Hub One then look no further than the BT HH5a version of router stats - see the link below.
It work out of the box, just add you router's password, wait for the helpdesk page to appear, click go and look at the different graphs on the various tabs. The one you want to watch is the SNRM tab.
I recommend a sample rate of 10 seconds and 720 plots per graph (2 hours). On a bad line, you get stuff like this...
"Your ISP is dropping the line..." as if!! Anything to avoid looking for a real fault.
I have also looked at your other thread here - https://community.plus.net/t5/Fibre-Broadband/User-Error-0x3-and-0x4-frequent-drops-OpenReach-given-... - which raises a query I will enquiry about.
In another browser tab, login into the Plusnet user portal BEFORE clicking the fault & ticket links
Superusers are not staff, but they do have a direct line of communication into the business in order to raise issues, concerns and feedback from the community.
If this post helped, please click the Thumbs Up and if it fixed your issue, please click the This fixed my problem green button below.
Re: Getting data from the Plusnet router
05-05-2022 10:42 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
@Townman Forgive the delay - my mental health took a dip this week and lots have just passed me by.
I use a Mac without Bootcamp and the odd Linux box so was stuck to find a package that would pull data from the Plusnet router hence my hack of the scripts to give me something that I could work with.
SNMP or telnet scripts are more my history but this cludge was an option and others may find it of use in the future.
Re: Getting data from the Plusnet router
05-05-2022 11:26 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Not my technology stack, but apparently Router stats will run under Wine on Linux - see How to run Routerstats in Linux (kitz.co.uk)
In another browser tab, login into the Plusnet user portal BEFORE clicking the fault & ticket links
Superusers are not staff, but they do have a direct line of communication into the business in order to raise issues, concerns and feedback from the community.
If this post helped, please click the Thumbs Up and if it fixed your issue, please click the This fixed my problem green button below.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- Re: Getting data from the Plusnet router