Created
September 17, 2010 03:55
-
-
Save joet3ch/583661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use Net::Ping; | |
use DBI; | |
use Data::Dumper; | |
use Net::DNS; | |
# script pings hosts (oh yea) | |
#---------DB Connection | |
my $server= 'localhost'; | |
my $db = 'dbname'; | |
my $username = 'dbuser'; | |
my $password = 'dbpass'; | |
my $dbh = DBI->connect("dbi:mysql:$db:$server", $username, $password); | |
#---------New Ping Object | |
my $p = Net::Ping->new("icmp"); | |
my $query = "select domain from ip"; | |
my $sth = $dbh->prepare($query); | |
$sth->execute(); | |
my @hosts; | |
while (my $row = $sth->fetchrow_arrayref) { | |
push @hosts, @$row; | |
} | |
foreach (@hosts) { | |
if ($p->ping($_)) { | |
my $alive = 'Y'; | |
my $insert = "update ip set alive=\"$alive\" where domain=\"$_\""; | |
my $ins = $dbh->prepare($insert); | |
$ins->execute(); | |
my $insertdate = "update ip set time=curtime() where domain=\"$_\""; | |
my $insdate = $dbh->prepare($insertdate); | |
$insdate->execute(); | |
} else { | |
my $alive = 'N'; | |
my $insert = "update ip set alive=\"$alive\" where domain=\"$_\""; | |
my $ins = $dbh->prepare($insert); | |
$ins->execute(); | |
} | |
} | |
$p->close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment