I run this from Cygwin under Windows XP Pro and it saves me as much aggravation as time; especially when (not if) the connection is lost and I have to log back in. If I was really smart I'd make this script run natively under Win32, detect the optimal network connection (100Mb Ethernet, open-access WiFi, T-Mobile HotSpot, loopback if all else fails) and setup my configuration for me thusly (change default SMTP in Outlook, update HOSTS file for external network access to intranet services, etc.). But, I'm not. I currently trigger this script manually when I am in a HotSpot zone. It works well enough.
Oh, in real life, I hard code my username and password. If someone gets my machine, my tmobile account is the least of my worries.
Update: removed unused use Data::Dumper and cleaned up gross spelling errors.#!/usr/bin/perl -w # tmobile.pl use strict; use LWP::UserAgent; use HTTP::Request::Common qw(:DEFAULT $DYNAMIC_FILE_UPLOAD); use HTTP::Cookies; use Logger::Simple; my ($username,$password) = @ARGV; my $i = 0; my $max_tries = 5; my %levels = (ERROR=>1, WARN=>4, INFO=>6, DEBUG=>9); my $loglevel = 'DEBUG'; print "level set to: $loglevel -- $levels{$loglevel}\n"; my $log=Logger::Simple->new(LOG=>"/var/log/tmobile.log",CARP=>'1'); $log->set("###### Start tmobile.pl v.01 ######") if $levels{"$loglevel"} > $levels{'WARN'}; my $ua = LWP::UserAgent->new; ## Just a little lie $ua->agent("Mozilla/4.0 (compatible; MSIE 5.5; MSN 2.5; Windows 98) ") +; $ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt", autosave => 1)); push @{ $ua->requests_redirectable }, 'POST'; $log->set("Attempting to Login") if $levels{"$loglevel"} > $levels{'WARN'}; ## ## In SoCal all the TMobile HotSpots I'd visited ## used "service1.hotspot.t-mobile.com" but ## in South TX I found "service3...", so let's ## iterate thru a bit. ## while (!login_to_tmobile(\$ua,$i) && $i < $max_tries) { $log->set("\tLogin retry # $i ... ") if $levels{"$loglevel"} > $levels{'WARN'}; $i++; sleep 3; # Let's not bang too hard... } exit 0; # Create a request, send it through UA and get result sub login_to_tmobile{ my ($ua, $j) = @_; $j++; print "trying $j..."; my $res = $$ua->request(POST "https://service$j.hotspot.t-mobile.co +m//user/home", Content_Type => "application/x-www-form-urlencoded", Content => [ username => $username, password => $password, ]); #Check the outcome of the response if ($res->is_success) { $log->set("Login successful!\n $res->content"); # always log print "Got it!\n"; return 1; } $log->set("Post failed with $res->status_line"); # always log print " nope: ",$res->status_line,"\n"; return 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Expresso Login
by rjamestaylor (Acolyte) on Dec 04, 2003 at 13:28 UTC | |
by rjamestaylor (Acolyte) on Dec 20, 2003 at 20:11 UTC |