check your ihug usage script

Discussion in 'NZ Computing' started by Shane, May 14, 2006.

  1. Shane

    Shane Guest

    Because someone posted a script on a linux mailing list, and because my
    mailserver/ip is currently banned by sorbs (and therefore I cant post to
    that mailing list!) because they think a static ip is a dynamic ip
    Assuming this is ok by ihug, as this script merely screen scrapes their
    usage page
    __end preamble__

    I am obeying the law that says, if anyone posts a script that does
    something, someone else will post a perl script doing the same thing :)


    My script works, you need perl installed (windows users)
    Anyways, you can use it, share it with your friends, skite about it to your
    dates, w/ever, there is no warranty, and you cant sue me if its borked
    __end ass covering__

    __start script__

    #!/usr/bin/perl -w
    use strict;
    use WWW::Mechanize;
    use HTML::TokeParser;

    #declare variables
    my $site = "https://the.ihug.co.nz/acnts/myaccounts.pl";
    my $site2 = "https://the.ihug.co.nz/acnts/myaccount-int.pl/usage";
    my $login = $ARGV[0] or die "Not enough arguments, usage ihug_usage.pl
    <username>";
    system "stty -echo";
    print "password: ";
    my $password = <stdin>;
    system "stty echo";
    print "\nFetching usage now\n\n";
    my @data;
    my ($agent, $element, $holder3);

    #Create instance of mechanize to use as our web agent
    $agent = WWW::Mechanize->new();
    #$agent->cookie_jar(HTTP::Cookies->new);
    $agent->get($site);

    #Ihugs Login Page
    $agent->form(1);
    $agent->field("login", $login);
    $agent->field("password", $password);
    $agent->submit();

    #We are logged in, lets go straight to the Usage page
    $agent->get($site2);
    $agent->form(2) or die "Error you are not logged in!!";
    $agent->click;

    # We are now at the current Data usage page
    # So Im putting the content through HTML::TokeParser, $deity knows why
    my $stream = HTML::TokeParser->new(\$agent->{content});

    #Lets do some regexp magic to get the contents of the cells of the table
    while ($stream->get_tag("td")){
    my $topbid = $stream->get_trimmed_text("/td");
    if ($topbid =~m/\d.$/){$topbid =~s/\[IMG\]//;push (@data, $topbid)}}

    #take the last 6 elements away from @data, and put them into @totals
    my $i;
    my @totals;
    for ($i=1;$i<8;$i++){push(@totals, pop @data)}

    #get number of elements left in array
    my $element_tot = @data;

    #start printing out the data we were after
    print "***********************************************************\n";
    #print to stdout our data usage
    my $heading = shift @data;
    print "$heading\n";
    print "***********************************************************\n\n";

    #loop to seperate each days usage into a single line
    my $t;
    for ($t=1;$t<($element_tot / 6);$t++){
    for ($i=1;$i<=6;$i++){
    $holder3 = shift @data;
    print "$holder3\t"}
    print "\n"
    }
    print "Today\t\t";
    for ($i=1;$i<6;$i++){
    $holder3 = shift @data;
    print "$holder3\t"}
    print "\n";

    print "\n";
    $element = pop @totals;
    print "National Onpeak $element\t\t";
    $element = pop @totals;
    print "National Offpeak $element\n";
    $element = pop @totals;
    print "International Onpeak $element\t";
    $element = pop @totals;
    print "International Offpeak $element\n";
    my $total_month = pop @totals;
    $element = pop @totals;
    print "Total Peak $element\t\t";
    $element = pop @totals;
    print "Total OffPeak $element\n";
    print "Total data this month $total_month\n\n";


    __end wannabe script__

    Directions
    Save to a file, named, ihug_usage.pl.
    Chmod +x <filename>
    Usage:
    someone@computer:~$<filename> <ihug username>

    it should spell itself out from there
    --
    Rule 6: There is no rule 6
    Shane, May 14, 2006
    #1
    1. Advertising

  2. Shane

    Shane Guest

    Shane wrote:

    > Because someone posted a script on a linux mailing list, and because my
    > mailserver/ip is currently banned by sorbs (and therefore I cant post to
    > that mailing list!) because they think a static ip is a dynamic ip
    > Assuming this is ok by ihug, as this script merely screen scrapes their
    > usage page
    > __end preamble__
    >
    > I am obeying the law that says, if anyone posts a script that does
    > something, someone else will post a perl script doing the same thing :)
    >
    >
    > My script works, you need perl installed (windows users)
    > Anyways, you can use it, share it with your friends, skite about it to
    > your dates, w/ever, there is no warranty, and you cant sue me if its
    > borked __end ass covering__
    >
    > __start script__
    >
    > #!/usr/bin/perl -w
    > use strict;
    > use WWW::Mechanize;
    > use HTML::TokeParser;
    >
    > #declare variables
    > my $site = "https://the.ihug.co.nz/acnts/myaccounts.pl";
    > my $site2 = "https://the.ihug.co.nz/acnts/myaccount-int.pl/usage";
    > my $login = $ARGV[0] or die "Not enough arguments, usage ihug_usage.pl
    > <username>";
    > system "stty -echo";
    > print "password: ";
    > my $password = <stdin>;
    > system "stty echo";
    > print "\nFetching usage now\n\n";
    > my @data;
    > my ($agent, $element, $holder3);
    >
    > #Create instance of mechanize to use as our web agent
    > $agent = WWW::Mechanize->new();
    > #$agent->cookie_jar(HTTP::Cookies->new);
    > $agent->get($site);
    >
    > #Ihugs Login Page
    > $agent->form(1);
    > $agent->field("login", $login);
    > $agent->field("password", $password);
    > $agent->submit();
    >
    > #We are logged in, lets go straight to the Usage page
    > $agent->get($site2);
    > $agent->form(2) or die "Error you are not logged in!!";
    > $agent->click;
    >
    > # We are now at the current Data usage page
    > # So Im putting the content through HTML::TokeParser, $deity knows why
    > my $stream = HTML::TokeParser->new(\$agent->{content});
    >
    > #Lets do some regexp magic to get the contents of the cells of the table
    > while ($stream->get_tag("td")){
    > my $topbid = $stream->get_trimmed_text("/td");
    > if ($topbid =~m/\d.$/){$topbid =~s/\[IMG\]//;push (@data, $topbid)}}
    >
    > #take the last 6 elements away from @data, and put them into @totals
    > my $i;
    > my @totals;
    > for ($i=1;$i<8;$i++){push(@totals, pop @data)}
    >
    > #get number of elements left in array
    > my $element_tot = @data;
    >
    > #start printing out the data we were after
    > print "***********************************************************\n";
    > #print to stdout our data usage
    > my $heading = shift @data;
    > print "$heading\n";
    > print "***********************************************************\n\n";
    >
    > #loop to seperate each days usage into a single line
    > my $t;
    > for ($t=1;$t<($element_tot / 6);$t++){
    > for ($i=1;$i<=6;$i++){
    > $holder3 = shift @data;
    > print "$holder3\t"}
    > print "\n"
    > }
    > print "Today\t\t";
    > for ($i=1;$i<6;$i++){
    > $holder3 = shift @data;
    > print "$holder3\t"}
    > print "\n";
    >
    > print "\n";
    > $element = pop @totals;
    > print "National Onpeak $element\t\t";
    > $element = pop @totals;
    > print "National Offpeak $element\n";
    > $element = pop @totals;
    > print "International Onpeak $element\t";
    > $element = pop @totals;
    > print "International Offpeak $element\n";
    > my $total_month = pop @totals;
    > $element = pop @totals;
    > print "Total Peak $element\t\t";
    > $element = pop @totals;
    > print "Total OffPeak $element\n";
    > print "Total data this month $total_month\n\n";
    >
    >
    > __end wannabe script__
    >
    > Directions
    > Save to a file, named, ihug_usage.pl.
    > Chmod +x <filename>
    > Usage:
    > someone@computer:~$<filename> <ihug username>
    >
    > it should spell itself out from there



    If you are wanting to run this on windows, the two lines
    system "stty -echo";
    and
    system "stty echo";
    need to be commented out with # signs, thus
    #system "stty -echo";
    and
    #system "stty echo";

    You will also need to install perl, nmake, www::mechanize, and crypt::ssleay
    perl for windows is found here:
    http://downloads.activestate.com/ActivePerl/Windows/5.8/ActivePerl-5.8.8.817-MSWin32-x86-257965.msi
    http://tinyurl.com/j5t5z

    nmake as per instructions here:
    http://johnbokma.com/perl/make-for-windows.html
    downloaded from here:
    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q132084

    www::mechanize from here:
    http://cpan.uwinnipeg.ca/module/WWW::Mechanize

    crypt::ssleay as per the instructions here:
    http://johnbokma.com/perl/https.html


    meh


    --
    Rule 6: There is no rule 6
    Shane, May 14, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a

    <script>alert();</script>

    =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a, Apr 13, 2004, in forum: Microsoft Certification
    Replies:
    0
    Views:
    7,811
    =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a
    Apr 13, 2004
  2. Alan

    Ihug incorrect usage meter?

    Alan, Apr 6, 2006, in forum: NZ Computing
    Replies:
    15
    Views:
    476
    Shane
    Apr 7, 2006
  3. iascoot
    Replies:
    5
    Views:
    385
    Vista
    Aug 11, 2006
  4. Dave Doe
    Replies:
    5
    Views:
    492
    Ralph Fox
    Apr 11, 2008
  5. Katipo
    Replies:
    2
    Views:
    452
    Geopelia
    Apr 10, 2008
Loading...

Share This Page