Post by Geoffrey F. GreenHTTP::Request
# Fetch the page
$admin = ARGV[0]; #password
print $admin,"\n";
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => 'http://192.168.0.1/status.htm');
$req->authorization_basic('', $admin); #not working
my $thePage = $ua->send_request($req);
but it doesn't seem to authenticate. i have tried various usernames: 'root'
, 'admin'. my logged in user name.
doesn't help.
that
authorization_basic($uname,$passwd)
I think will need to get a username stuffed into it,
and the passwd....
now the way i got around that was with the simple, to start with
case of running my 'own' little authenticator - see below for it
and nested that in the $ua
$ua->credentials($uri->host_port, $realm, $user, $pword)
and skipped the $req->auth... stuff...
So the solution is for you to resolve how you login to your
router - since that is the Username and Passwd that it is
going to be expecting to see...
I did this stuff in the function
dtk_cmd_page_parser
in
http://www.wetware.com/drieux/src/unix/perl/UglyCode.txt
ciao
drieux
---
this is how I did the basic authentication for myself at
the command line...
#-------------------------
# OK - so the perldoc says rip this off and use it
# so I did - it will get me the dope I need - you will need to
# have the libwww-perl release to have the specific piece of code
# but this is way cool. Clearly I should have implemented the GetOpt
# solution that would be cooler.
sub gbc {
my($realm, $uri) = @_;
# if ($main::options{'C'}) {
# return split(':', $main::options{'C'}, 2);
# } elsif (-t) {
if(-t) { # are we attached to a tty???
my $netloc = $uri->host_port;
print "Enter username for $realm at $netloc: ";
my $user = <STDIN>;
chomp($user);
return (undef, undef) unless length $user;
print "Password: ";
system("stty -echo");
my $password = <STDIN>;
system("stty echo");
print "\n"; # because we disabled echo
chomp($password);
return ($user, $password);
} else {
return (undef, undef)
}
} # end gbc - the get_basic_credentials