报表结果:
******************************************************
+--------------------------------------------------------------------------------------------------+
| Time: 23:26:31 |
| HOST STATUS RESPONSE |
+---------------------------------------------------------------------------------------------------+
| http://www.yahoo.com/ ACCESsed Response 1 seconds |
| http://www.hotmail.com/ ACCESSED Response 1 seconds |
| http://www.ebay.com/ ACCESSED Response 1 seconds |
| http://www.example.com/ ACCESSED Response 0 seconds |
| http://www.not/ a real site.com WRONG N/A |
+---------------------------------------------------------------------------------------------------+
| Time: 23:30:17 |
| HOST STATUS RESPONSE |
+----------------------------------------------------------------------------------------------------+
| http://www.yahoo.com/ ACCESSED Response 0 seconds |
| http://www.hotmail.com/ ACCESSED Response 0 seconds |
| http://www.ebay.com/ ACCESSED Response 1 seconds |
| http://www.example.com/ ACCESSED Response 0 seconds |
| http://www.not/ a real site.com WRONG N/A |
+------------------------------------------------------------------------------------------------------+
| Time: 23:31:26 |
| HOST STATUS RESPONSE |
+-------------------------------------------------------------------------------------------------------+
| http://www.yahoo.com/ ACCESSED Response 0 seconds |
| http://www.hotmail.com/ ACCESSED Response 1 seconds |
| http://www.ebay.com/ ACCESSED Response 0 seconds |
| http://www.example.com/ ACCESSED Response 0 seconds |
| http://www.not/ a real site.com WRONG N/A |
perl代码:
#!/usr/bin/perl
use warnings;
use strict;
use Tie::File;
use Net::SMTP;
use LWP::UserAgent;
#################################################################
# Program Settings
#
my $error_log = 'Responser_errors.txt';# File to store errors of program
my $input_file = 'urls.txt'; # From where program will read WEB Addresses
my $smtp_file = 'SMTP_Settings.txt'; # File for SMTP Settings
my $response_limit = 12; #In Seconds # Positively diggit -> sendmail;
# 0 -> will not send mail
my $send_mail = 1; # my $send_mail = 1; ->SMTP option is ON,
# my $send_mail = 0; ->SMTP option is OFF
##################################################################
# END OF SETTINGS
# Do not edit bellow if you dont understand it.
##################################################################
die "File $input_file is not existn" unless (-e $input_file);
die "SMTP is ON, but file $smtp_file is not existn" unless (-e $smtp_file);
my $localtime = localtime;
our @errors;
my ($day,$month,$date,$hour,$year) = split /s+/,scalar localtime;
my $output_file = 'report-'.$date.'.'.$month.'.'.$year.'.txt';
my ($smtp_host,$recipient,$reverse_path, @all_addr) = ();
tie @all_addr, 'Tie::File',
$input_file or error("Cant open $input_file to read addresses");
if (-e $output_file) {
open(OUT,">> $output_file")
or error("Cant open exist file $output_file for append");
} else {
open(OUT,"> $output_file")
or error("Cant open new file $output_file for writting");
}
my @smtp_settings;
if ($^O =~ /win/i) {
tie @smtp_settings, 'Tie::File', $smtp_file,,
recsep => "