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
|
#!/usr/bin/perl
#
# AGI Script that prompts the user for an ip address, pings the ip, and reports back to the user.
#
# Requires the Asterisk::AGI and Net::Ping::External perl modules
#
# Written by: James Golovich <james@gnuinter.net>
#
#
use Asterisk::AGI;
use Net::Ping::External qw(ping);
$AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my $finished = 0;
$AGI->exec('Festival', '"Enter the eye-p address you wish to ping."');
my $ipaddr = '';
my $x = 0;
while (!$finished) {
my $input = chr($AGI->wait_for_digit('5000'));
if ($input =~ /^[0-9\*\#]$/) {
if ($input =~ /^[\*\#]$/) {
$x++;
if ($x > 3) {
$finished = 1;
} else {
$ipaddr .= '.';
}
} else {
$ipaddr .= $input;
}
} else {
#must have timed out
$finished = 1;
}
if ( length($ipaddr) > 14) {
$finished = 1;
}
}
if ($ipaddr !~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) {
$AGI->exec('Festival', "\"Invalid Address: $ipaddr\"");
exit 0;
}
$AGI->exec('Festival', '"Please wait"');
if (ping(host => "$ipaddr", timeout => 2)) {
$AGI->exec('Festival', '"Host is up"');
} else {
$AGI->exec('Festival', '"Host is down"');
}
|