4th Floor, 4 Tabernacle Street London EC2A 4LU

Get HTTP Code Response – Perl

Pass the script many hosts and obtain the HTTP response codes for the pages.
[bash]

./http_check.pl …

[/bash] [perl]

use LWP::UserAgent;

print get_url($url);

sub get_url ($)
{
my $url = shift;

my $ua = LWP::UserAgent->new;

my $req = HTTP::Request->new(GET => $url);
my $res = $ua->request($req);

return $res->code;
}

##Some other useful returns:
# return $res->code;
# return $res->status_line;
# return $res->is_success;

[/perl]