IPv4 Fremnet Logo
TOOLS, TINKERINGS & CODE

Love me

Virgin Broadband - Usage meter in PERL · Nov 12, 19:56 by Shannon Wynter

Greetings folks..

While this isn’t a complete usage meter (as the title leads one to believe) it is a huge step in the right direction.

Basically reading the code below should make it fairly easy to understand the procedure for gathering information from Virgin Mobile’s usage system.

If I get time I’ll port it to javascript and pascal (for Delphi) – in the mean time I’m sure someone can use it…

  1. #!/usr/bin/perl -w  
  2.   
  3. use LWP;  
  4. use XML::Simple;  
  5. use Data::Dumper;  
  6. use strict;  
  7.   
  8. # Configuration - Specify your username and password here  
  9. my $USERNAME = 'yourusername';  
  10. my $PASSWORD = 'yourpassword';  
  11.   
  12. my $agent = LWP::UserAgent->new;  
  13.   
  14. # Not sure if it works without cookies, wasn't going to try  
  15. $agent->cookie_jar({});  
  16.   
  17. # Authenticate  
  18. my $xmlAuth = doPost( 'auth', [  
  19. action   => 'authenticate',  
  20. password => $PASSWORD,  
  21. username => $USERNAME  
  22. ] );  
  23.   
  24. die "Authentication Failure\n" if ($xmlAuth->{authenticated} != 1);  
  25.   
  26. print "Authenticated as: ", $xmlAuth->{username}[1], "\n";  
  27.   
  28. # Get the customer ID (I don't know why we jump through so many hoops, but hey)  
  29. my $xmlCustID = doPost( 'service', [  
  30. action   => 'get_customer_id',  
  31. username => $xmlAuth->{username}[1]  
  32. ] );  
  33.   
  34. die $xmlCustID->{error}, "\n" if ($xmlCustID->{error});  
  35.   
  36. print "Customer ID: ", $xmlCustID->{customer_id}, "\n";  
  37.   
  38. # Now get the list of services, this returns all services including email addresses.  
  39. my $xmlServices = doPost( 'service', [  
  40. action      => 'get_services',  
  41. customer_id => $xmlCustID->{customer_id}  
  42. ] );  
  43.   
  44. print Dumper($xmlServices);  
  45.   
  46. # Shortcut post method, saves code (c:  
  47. sub doPost {  
  48. my $page = shift;  
  49. my $data = shift;  
  50.   
  51. my $response = $agent->post(  
  52.   'http://mybroadbandusage.virginbroadband.com.au/cgi-bin/ajax/'.$page.'.cgi', $data  
  53. );  
  54.   
  55. die "HTTP Error: ", $response->status_line unless $response->is_success;  
  56.   
  57. return XMLin $response->content;  
  58. }
  59. Download this code: virgin_usage.pl (Downloaded 142 time(s))

Comments

Spam no more - rel=nofollow is active here, spamming my comments will not help your page rank.

  Textile help
---== Copyright Shannon Wynter - All rights reserved - All wrongs avenged ==---