#!/usr/bin/perl -w use strict; #use warnings; use Getopt::Long; use LWP::UserAgent; use LWP::Protocol::https; use LWP::UserAgent::DNS::Hosts; use Crypt::SSLeay; use Mozilla::CA; GetOptions( 'hostname|h=s' => \my $hostname1, 'IPAddress|i=s' => \my $ipaddress1, 'uri|u=s' => \my $URI, 'searchstring|s=s' => \my $searchstring, 'help|?' => sub { &usage(); }, ); my $webpage = "https://$hostname1/$URI"; my $returnvalue; LWP::UserAgent::DNS::Hosts->register_host( "$hostname1" => "$ipaddress1", ); LWP::UserAgent::DNS::Hosts->enable_override; my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 }); $ua->protocols_allowed( ['https'] ); $ua->agent('Mozilla/8.0'); my $res = $ua->get($webpage); #returns http status print "HTTP status: ", $res->status_line( ), " "; #Example of header elements that can be polled #print "Header: ", $res->header('Server'), "\n"; my $response=''; my $result = $res->content; if ( $result =~ /$searchstring/ ) { print "\""."$searchstring" . "\" found on " . "$webpage" . " at " . "$ipaddress1" . "\n"; $returnvalue='0'; }else{ print "\""."$searchstring" . "\" not found on " . "$webpage" . " at " . "$ipaddress1" . "\n"; $returnvalue='2'; } sub usage() { print(" Content checking script Example usage: ./content_check.pl --hostname=www.verisign.com --IPAddress=69.58.181.89 --uri=products-services/ --searchstring='Products and Services' --host= Hostname to connect to. --ip= IP address to use if unable to use DNS lookup to test. Ex. Site is behind a load balancer and you want to test one of the webheads. --uri= URI path relevant to the hostname. --searchstring= String of test to base content check off of. --help Displays this page. "); } exit($returnvalue);