Script to see if important net devices are available on the
net.
cron job set to run every 5 minutes
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/bin/hostck.pl
#!/usr/local/bin/perl
use strict;
require '/usr/local/lib/perl5/5.6.1/.pl';
my $MAILTO = "chaunceyt";
my $pid = &("OUTPUT","INPUT","/usr/local/sbin/fping -u");
# get ipaddress of important devices...
my @check = (`cat /etc/ipaddress`);
foreach(@check) {
print INPUT "$_\n";
}
close(INPUT);
my @output = ();
close(OUTPUT);
if ($#output != -1) {
my $date = "";
chop($date = `date`);MAIL,"|mail -s 'Hosts down...' $MAILTO");
print MAIL "\nHosts down as of: $date\n\n";
print MAIL @output;
close MAIL;
}
Discovery script, used to see what ip stations are running
Output file is processed by donmap
#!/usr/bin/perl
$fping = "/usr/local/sbin/fping";
# file containing all internal subnets
@aliveNet = `cat netaddress`;
foreach $network (@aliveNet) {OUTFILE, ">> netscan.out") or die "Unable toOutput file\n";
chomp $network;
($oct1, $oct2, $oct3, $oct4) = split(/\./, $network);
$net = "$oct1.$oct2.$oct3";
for $host (1..254) {
push(@netList, "$net.$host");
}
$aliveHosts = `$fping -a @netList`;
@netList = ();
print OUTFILE "$aliveHosts";
close OUTFILE;
}
Script to determine port running on IP's discovered
#!/usr/bin/perl
$nmap = "/usr/local/bin/nmap";
@getaddr = `cat netscan.out`;
foreach $ip (@getaddr) {OUTFILE, ">> nmapscan.out") or die "Unable toOutput file\n";
chomp $ip;
$nmapdata = `$nmap $ip -O`;
print OUTFILE "$nmapdata";
print OUTFILE "%";
close OUTFILE;
}
|