#!/usr/bin/perl -w # get_bw.pl # # Log's into orbit.theplanet.com and gets current traffic usage use strict; use WWW::Mechanize; use HTML::TokeParser; # Login Info my $login = 'username'; my $passwd = 'password'; my $host = 'hostname'; # chart info my $bwimg = '/remote/folder/path/image_name.png'; my $end = time(); my $begin = $end - 86400; # 1 day # Get the information in brackets from the Orbit bandwidth page my $chart = "https://orbit.theplanet.com/nav_hardware/rtg_img.php?graph=[IP]&table=[TABLE]&iid=[IID]&begin=$begin&end=$end&title1=TO_INTERNET&title2=FROM_INTERNET"; #### Shouldn't have to touch below # User Agent my $a = WWW::Mechanize->new(); $a->agent_alias('Mac Mozilla'); # TokeParser my $stream; # Login login(); # Get Bandwidth $a->get('https://orbit.theplanet.com/nav_hardware/a1_bandwidth_utilization.html'); $stream = HTML::TokeParser->new(\$a->content()); while(my $token = $stream->get_tag('td')) { my $text = $stream->get_text(); if($text =~ /^Quick RAW Usage: /) { my @t = split(' ', $text); print "$host bw:\n"; print $t[3] . 'GB, '; printf('%3.1f%%', $t[3]/12); } } $a->get($chart, ':content_file'=>$bwimg); #### Subs # Login sub login { $a->get('https://orbit.theplanet.com/'); $a->field('username', $login); $a->field('password', $passwd); $a->submit(); }