Specifyig username and password in PERL

T

tandon.sourabh

Is there a way to navigate through a secure website (https) where I
have the username and password? I know the exact URL but do not know
how to specify the username and password in the PERL script so that
the website allows me in.
 
M

Michael Austin

Is there a way to navigate through a secure website (https) where I
have the username and password? I know the exact URL but do not know
how to specify the username and password in the PERL script so that
the website allows me in.


Similar to logging into a linksys router and getting the current IP??

You will need to make the mods to use HTTPS/port 443

Here is a pretty good example:

#!/usr/bin/perl -w
#!/usr/local/bin/perl -w

## $ENV{'PATH'} = (exists($ENV{PATH}) ? "$ENV{PATH}:" : "") .
"/sbin:/usr/sbin:/
bi
## n:/usr/bin:/etc:/usr/lib:";

use Getopt::Long;
use Sys::Hostname;
use IO::Socket;

sub encode_base64 ($;$) {
my $res = '';
my $eol = $_[1];
$eol = "\n" unless defined $eol;
pos($_[0]) = 0; # ensure start at the
beginning
while ($_[0] =~ /(.{1,45})/gs) {
$res .= substr(pack('u', $1), 1);
chop($res);
}
$res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs

# fix padding at the end
my $padding = (3 - length($_[0]) % 3) % 3;
$res =~ s/.{$padding}$/'=' x $padding/e if $padding;

# break encoded string into lines of no more than 76 characters each
if (length $eol) {
$res =~ s/(.{1,76})/$1$eol/g;
}
$res;
}

$0 = "findIP";
my $version = "3.5.4";
my $programd = $0;
$programd =~ s%^.*/%%;
my $program = $programd;
$program =~ s/d$//;
my $now = time;
my $hostname = hostname();
my ($peer, $server, $port);
my ($sd, $rq, $request, $reply);
my $url = "HTTP://192.168.1.1:80/Status_Router.asp";

$url =~ s%^HTTP://%%i;
$server = $url;
$server =~ s%/.*%%;
$url = "/" unless $url =~ m%/%;
$url =~ s%^[^/]*/%%;

## determine peer and port to use.
$peer = $server;
$peer =~ s%/.*%%;
$port = $peer;
$port =~ s%^.*:%%;
$port = 80 unless $port =~ /^\d+$/;
$peer =~ s%:.*$%%;

#### username not required for linksys, so anything will work here
#### you just need to enter your password.
my $auth = encode_base64("admin:mypassword");

$request = "GET ";
# $request .= "HTTP://$server";
$request .= "/$url HTTP/1.0\n";
# $request .= "Host: $server\n";
$request .= "Authorization: Basic $auth";
$request .= "User-Agent: ${program}/${version}\n";
$request .= "Connection: open\n";
$request .= "\n";

## make sure newlines are <cr><lf> for some pedantic proxy servers
($rq = $request) =~ s/\n/\r\n/g;
# printf("$rq");

local $^W = 0;
$sd = IO::Socket::INET->new(PeerAddr => $peer,
PeerPort => $port,
Proto => 'tcp');
my $skip='interipaddr';
my $DNS1='script>1';
my $DNS2='script>2';
my $DNS3='script>3';
my $result = send $sd, $rq, 0;
if ($result != length($rq)) {
printf("cannot send to 192.168.1.1:80 ($!).\n");
} else {
while ($_ = <$sd>) {
# verbose("RECEIVE:", "%s", define($_, "<undefined>"));
$reply .= $_ if defined $_;
}
# printf(" $reply\n");
if ($reply =~
/${skip}.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/is)
{
$WANip = $1;
}
if ($reply =~
/${DNS1}.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/is)
{
$DNS1 = $1;
}
if ($reply =~
/${DNS2}.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/is)
{
$DNS2 = $1;
}
if ($reply =~
/${DNS3}.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*/is)
{
$DNS3 = $1;
}
printf("Current IP address is: $WANip\n");
printf("DNS 1 IP address is: $DNS1\n");
printf("DNS 2 IP address is: $DNS2\n");
printf("DNS 3 IP address is: $DNS3\n");
close($sd);
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top