orangesquid (os) wrote,
orangesquid
os

web-scraping script for cacti (or anything, really) modified for motorola surfboard 5120 (since comcast "helpfully" disables snmp)...

#!/usr/bin/perl
use warnings;
use strict;

use LWP::Simple;

my %data;
my %trash;
my @keys = qw(DownFreq DownSNR DownPower UpFreq UpPower DownQAM DownNACO UpChan UpServ UpSym);
my $content = LWP::Simple::get("http://192.168.100.1/signaldata.htm") or die "Couldn't get it!";
$content =~ s/\ //g;

# regex in html source order
if ($content =~ /(<td>Frequency<\/td>)/gi) { $trash{a} = $1};
if ($content =~ /<td>(-?\d+)\sHz\s*<\/td>/gi) { $data{DownFreq} = $1; }
if ($content =~ /(<td>Signal To Noise Ratio<\/td>)/gi){ $trash{a} = $1};
if ($content =~ /<td>(-?\d+)\sdB\s*/gi) { $data{DownSNR} = $1; }
if ($content =~ /(<td>QAM<\/td>)/gi) { $trash{a} = $1};
if ($content =~ /<td>([^<]+)\s*/gi) { $data{DownQAM} = $1; }
if ($content =~ /(<td>Network Access Control Object<\/td>)/gi) { $trash{a} = $1};
if ($content =~ /<td>([^<]+)\s*/gi) { $data{DownNACO} = $1; }
if ($content =~ /(<td>Power Level<\/td>)/gi) { $trash{a} = $1};
if ($content =~ /<td>(-?\d+)\sdBmV\s*/gi) { $data{DownPower} = $1; }
if ($content =~ /(<td>Channel ID<\/td>)/gi) { $trash{a} = $1};
if ($content =~ /<td>(-?\d+)<\/td>/gi) { $data{UpChan} = $1; }
if ($content =~ /(<td>Frequency<\/td>)/gi) { $trash{a} = $1};
if ($content =~ /<td>(-?\d+)\sHz\s*<\/td>/gi) { $data{UpFreq} = $1; }
if ($content =~ /(<td>Ranging Service ID<\/td>)/gi) { $trash{a} = $1};
if ($content =~ /<td>(-?\d+)<\/td>/gi) { $data{UpServ} = $1; }
if ($content =~ /(<td>Symbol Rate<\/td>)/gi) { $trash{a} = $1};
if ($content =~ /<td>(-?[0-9.]+)\s*Msym\/s\s*/gi) { $data{UpSym} = $1; }
if ($content =~ /(<td>Power Level<\/td>)/gi) { $trash{a} = $1};
if ($content =~ /<td>(-?\d+)\sdBmV\s*/gi) { $data{UpPower} = $1; }

for (@keys) { print "$_:$data{$_} "; }

print "\n";

Tags: code, comcast, motorola, mrtg, perl, surfboard
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments