Thread: Superhub +11dBmV DS - Power level(s)
View Single Post
Old 07-10-2011, 15:02   #15
Milambar
Inactive
 
Join Date: Jan 2008
Posts: 954
Milambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond reputeMilambar has a reputation beyond repute
Re: +11dBmV DS - Power level(s)

For those who may be interested, this is a really simple (and somewhat hacky) perl program that will log in to the superhub, interrogate the stats page, and output the power and noise levels.

The program could easily be modified to store the data in a database for graphing.

Code:
#!/usr/bin/perl
#
# (*) Released into the PUBLIC DOMAIN on 07/10/2011.
# (*) Use at your own risk. No garuntees made.
# (*) Note: A bug; The SH also uses a 302 for an invalid login. Need to think of a workaround.

use strict;								# Enforce variable scoping.
use LWP::UserAgent;						# Module for retrieving webpages from a PSN.
use HTTP::Response;						# Module for processing a webpage retrieved by LWP. Not needed, but it simplifies things.
use HTML::TreeBuilder;					# Currently unused, but left in so I can investigate its capabilities later.
use Data::Dumper;						# Used for debug output, can be removed once the program works.

USER_CONFIGURATIONS:
	# Define the superhub login credentials here.
	# The defaults will work UNLESS you have changed the superhubs login name/password.
	my %credentials = (
		'loginUsername'		=> 'admin',
		'loginPassword'		=> 'changeme'
	);

	my $superFlub = '192.168.0.1';			# IP address of the router on your network.

####################################################################################################################
################### You shouldn't need to alter anything below this line. ##########################################
####################################################################################################################

INTERNAL_CONFIGURATIONS:
	my $loginPage = "/goform/valogin";		# Address of the login handler.
	my $statsPage = "/RgConnect.asp";	    # Address of the page containing the stats you want.
	my $uri		  = "http://";				# For completeness. Its unlikely to require changing.
	my @power;								# Global scope for use later.
	my @noise;								# Global scope for use later.
	my $ua = LWP::UserAgent->new;			# Create a new instance of LWP::UserAgent

SUPERHUB_LOGIN:
	# We now use the LWP object to send a post request to the server. It returns a HTML::Response object.
	my $login = $ua->post("${uri}${superFlub}$loginPage", ["loginUsername"=>$credentials{loginUsername}, "loginPassword"=>$credentials{loginPassword}]);

RETRIEVE_STATISTICS:
	if ($login->code != 302) {
		# Superhub Login failed. Report this to STDOUT and terminate.
		print "\nThere was an error logging into the router.\n";
		exit;
	} else {
		# Got a valid login, now retreieve and process the statistics page.
		my $sp = $ua->get("${uri}${superFlub}$statsPage");
		if ($sp->code != 200) {
			# Superhub failed to supply us with the statistics page. Report to STDOUT and terminate.
			print "\nRetrieval failure.\n";
			exit; 
		}
		
		# Convert the response object into a HTML content object. This is an implicit call
		# to HTML::Response. This is required, as the $sp object is blessed (private object).
		my $content = $sp->content;
		
		# This is a really HACKY way of retrieving the numeric values for Power and SNR.
		# Must investigate TreeBuilder for a cleaner method. But, despite that, it works.
		while ($content =~/(\d+\.\d+)\sdBmV/g) {
			push (@power, $1);
		}
		while ($content =~/(\d+\.\d+)\sdB\</g) {
			push (@noise, $1);
		}
	}

OUTPUT_DATA:
	print "Downstream\n";
	print "Channel 1\t$power[0]\t$noise[0]\n";
	print "Channel 2\t$power[1]\t$noise[1]\n";
	print "Channel 3\t$power[2]\t$noise[2]\n";
	print "Channel 4\t$power[3]\t$noise[3]\n";

	print "Upstream\n";
	print "Channel 1\t$power[8]\n";
Milambar is offline   Reply With Quote