1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| # Declaration des variables
$mailserver = "";
$domain = "";
$mail_to = "";
$mail_from = "";
$log_file = "";
$gateway = "";
$dns1 = "";
$dns2 = "";
my $a = "";
my $p = "";
# loading modules SMTP
use Net::SMTP;
use Time::HiRes qw( sleep usleep gettimeofday tv_interval);
# Open a log file
open (LOG, "> $log_file");
# run stuff and write on the log file
#.:::::::::::::::::::::::::::::::::::::: IPCONFIG ::::::::::::::::::::::::::::::::::::::::::::::::::::::::.
print LOG (".:: Test = Ipconfig ::. \n\n");
@table=`c:\\windows\\system32\\ipconfig.exe /all `;
print LOG ("@table \n\n");
print ("@table \n\n");
foreach $line (@table) { print LOG $line if $line =~ /Gateway . . . . . . . . . : (\d+\.\d+\.\d+\.\d+)/;
$gateway = $1;
}
foreach $line (@table) { print LOG $line if $line =~ /DNS Servers . . . . . . . . . . . : (\d+\.\d+\.\d+\.\d+)/;
$dns1 = $1;
}
print LOG ("DNS Server address : ",$dns1);
print ("DNS Server address : ",$dns1, " \n\n\n" );
# .::::::::::::::::::::::::::::::::::::: Test PING GATEWAY ::::::::::::::::::::::::::::::::::::::::::::::::.
print LOG (".:: Test = Ping Gateway: $gateway ::.\n");
print (".:: Test = Ping Gateway: $gateway ::. \n\n");
use Net::Ping;
$p = Net::Ping->new();
$a= $p->ping("$gateway");
for ($i=0;$i<10; $i++){
sleep 0.5;
$t0 = gettimeofday;
$a=$p->ping($gateway);
$t1=(gettimeofday - $t0);
print (" $gateway is alive. $t1 ms \n");
#print LOG ("$gatway is alive. $t1 ms \n");
}
if( $a eq '')
{
print "\n gateway is not alive \n";
print LOG "\n gateway is not alive \n";
}
else
{
print "\n gateway is alive \n";
print LOG "\n gateway is alive \n";
}
$p->close();
# .::::::::::::::::::::::::::::::::::::: Test NSLOOKUP ::::::::::::::::::::::::::::::::::::::::::::::::.
#.::::::::::::::::::::::::::::::::::::: Mail Sender ::::::::::::::::::::::::::::::::::::::::::::::::.
# Open a file log and send an e-mail
$smtp = Net::SMTP->new($mailserver, Hello => $domain);
$date = localtime();
$smtp->mail($mail_from);
$smtp->to($mail_to);
$smtp->data();
$smtp->datasend("Subject: Test: $date\n\n");
foreach ($gateway) {
$smtp->datasend("$_");
}
$smtp->dataend();
$smtp->quit;
# FIN
close LOG; |
Partager