Skip to content

Instantly share code, notes, and snippets.

@joet3ch
Created September 17, 2010 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joet3ch/583661 to your computer and use it in GitHub Desktop.
Save joet3ch/583661 to your computer and use it in GitHub Desktop.
#!/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