Skip to content

Instantly share code, notes, and snippets.

@rubemlrm
Created June 9, 2020 22:33
Show Gist options
  • Save rubemlrm/7e62c5edfe3b6c6898664891c92298e7 to your computer and use it in GitHub Desktop.
Save rubemlrm/7e62c5edfe3b6c6898664891c92298e7 to your computer and use it in GitHub Desktop.
CheckNetworkMachines.pl
#!/usr/bin/perl
use warnings;
use strict;
use Net::Ping;
use autodie;
my $host;
my $my_addr="<ip>";
my $ping;
my @reportlist;
chomp(my $date = `date +%a%d%m%y%k%M`);
open(FILE, "<ficheiro com ips>");
chomp (my @ips = <FILE>);
close(FILE);
foreach $host (@ips){
$ping = Net::Ping->new();
if ($ping->ping($host)){
#print "$host -> está activo.n";
push(@reportlist,"$host -> está activo.");
}else{
#print "$host -> está offlinen";
push(@reportlist,"$host -> está offline.");
}
$ping ->close();
}
#Reporte da lista
foreach (@reportlist)
{
print "$_n";
}
#para um ficheiro a ser enviado por mail</p>
open(FILE , ">../logs/'$date_machine_networking_report.txt'");
foreach (@reportlist){
print FILE "$_n";
}
close(FILE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment