Test http pl

From Federal Burro of Information
Jump to navigationJump to search

test_http.pl

#!/usr/bin/perl -w
# $Author: staradm $
# $Date: 2006/03/28 14:07:00 $
# $Id: test_http.pl,v 1.3 2006/03/28 14:07:00 staradm Exp $
# $Name:  $
# $Revision: 1.3 $
# $State: Exp $
use strict;

require HTTP::Request;
require LWP::UserAgent;

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

$ua->credentials(
    '192.168.1.30:443',
    'Restricted Files',
    'staradm' => 'XXX'
  );

my ( $sec, $min, $hour, $day, $month, $year ) = ( localtime ) [ 0, 1, 2, 3, 4, 5 ];

# my $stamp = $sec. $min. $hour. $day. $month. $year;
my $stamp = ($year+1900).".".$month.".". $day.".". $hour.".". $min.".". $sec;

my $vat  = "https://81.171.194.30/cgi-bin/printenv";
my $picc = "https://81.171.235.115/cgi-bin/printenv";

my $request = HTTP::Request->new(GET => $picc);
my $r = $ua->request($request);

my @myarr  = split(/\n/,$r->content) ;
my $HTTPVAR = 0;

foreach my $line ( @myarr ) {
        if ( $line =~ /^SERVER_ADDR/i) {
                $HTTPVAR = $line
        }
}
printf "%-10s %-32s %-32s\n", $stamp, $r->status_line, $HTTPVAR;