The iGuard IP250E requires cookies for authentication. Modifying Part 3's script is pretty simple. Below are just the additional code chunks. Whole script is available here.
use HTML::Form;
use HTTP::Cookies;
Add these to your includes.
my $ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new(file => "/tmp/iguard-ip250e.txt", autosave => 1));
$ua->agent("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.13) Gecko/2009080317 Fedora/3.0.13-1.fc10 Firefox/3.0.13");
Here we tell our useragent object where to store any cookies.
my $uri = 'http://192.168.1.243/image.cgi';
my $res = $ua->request(HTTP::Request->new(GET => $uri));
my $status = $res->status_line;
printf LOG "unable to process initial cookie request, status code is: %s", $status
unless $status eq '200 OK' || $status eq '302 Found';
my ($form) = HTML::Form->parse($res);
print LOG "form: ", Dumper($form) if DEBUG;
$form->value('$login_un' => 'username');
$form->value('$login_pw' => 'password');
On the iGuard IP250E, there's a simple login form returned if you request image.cgi We parse the form and assign the username/password params.
$res = $ua->request($form->click);
$status = $res->status_line;
printf LOG "unable to submit username/password, status code is: %s", $status
unless $status eq '200 OK' || $status eq '302 Found';
$uri = 'http://192.168.1.243/showimg_pda.cgi?cam=1';
my $im = Image::Magick->new();
Submit the form by issuing click. The URI showimg_pda.cgi?cam=1 is the way to return just the image from the iGuard. The rest of the code is the same.