cancel
Showing results for 
Search instead for 
Did you mean: 

Getting data from the Plusnet router

adbeasley
Grafter
Posts: 43
Thanks: 1
Registered: ‎21-03-2022

Getting data from the Plusnet router

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.

 

Creative Commons Licence
This software is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

 

11 REPLIES 11
jab1
Legend
Posts: 19,054
Thanks: 6,243
Fixes: 287
Registered: ‎24-02-2012

Re: Getting data from the Plusnet router

Why go to that trouble - it is all available direct from the Hub interface?

HubOneTroubleshootingHelpDesk.png

John
dvorak
Moderator
Moderator
Posts: 29,716
Thanks: 6,593
Fixes: 1,485
Registered: ‎11-01-2008

Re: Getting data from the Plusnet router

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.
Customer / Moderator
If it helped click the thumb
If it fixed it click 'This fixed my problem'
jab1
Legend
Posts: 19,054
Thanks: 6,243
Fixes: 287
Registered: ‎24-02-2012

Re: Getting data from the Plusnet router

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.

John
adbeasley
Grafter
Posts: 43
Thanks: 1
Registered: ‎21-03-2022

Re: Getting data from the Plusnet router


@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.

 

adbeasley
Grafter
Posts: 43
Thanks: 1
Registered: ‎21-03-2022

Re: Getting data from the Plusnet router


@jab1 wrote:

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.


When OpenReach say its the ISP dropping you 28+ times a month (6-8 per day some times) then ANY data is an advantage...

jab1
Legend
Posts: 19,054
Thanks: 6,243
Fixes: 287
Registered: ‎24-02-2012

Re: Getting data from the Plusnet router

If OR said that to me, I'd be somewhat suspicious, to be truthful.

John
Baldrick1
Moderator
Moderator
Posts: 12,356
Thanks: 5,543
Fixes: 430
Registered: ‎30-06-2016

Re: Getting data from the Plusnet router

@jab1 

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'

jab1
Legend
Posts: 19,054
Thanks: 6,243
Fixes: 287
Registered: ‎24-02-2012

Re: Getting data from the Plusnet router

Of course not, @Baldrick1  - they'd never do anything as underhand as that, would they?🤣

John
Townman
Superuser
Superuser
Posts: 23,910
Thanks: 10,131
Fixes: 174
Registered: ‎22-08-2007

Re: Getting data from the Plusnet router

@adbeasley 

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...

RSHub-NoiseMargin-20220429-221131.jpg

"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.

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.

adbeasley
Grafter
Posts: 43
Thanks: 1
Registered: ‎21-03-2022

Re: Getting data from the Plusnet router

@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.

Townman
Superuser
Superuser
Posts: 23,910
Thanks: 10,131
Fixes: 174
Registered: ‎22-08-2007

Re: Getting data from the Plusnet router

Not my technology stack, but apparently Router stats will run under Wine on Linux - see How to run Routerstats in Linux (kitz.co.uk)

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.