Skip to content

Instantly share code, notes, and snippets.

@rubemlrm
Last active October 2, 2015 18:08
Show Gist options
  • Select an option

  • Save rubemlrm/2292206 to your computer and use it in GitHub Desktop.

Select an option

Save rubemlrm/2292206 to your computer and use it in GitHub Desktop.
Check Network machines
#!/usr/bin/perl
package networking;
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`);
sub VerificarMaquinasRede(){
open(FILE, "../files/listagem_ip_rede.txt");
chomp (my @ips = <FILE>);
close(FILE);
foreach $host (@ips){
$ping = Net::Ping->new();
if ($ping->ping($host)){
#print "$host -&amp;amp;gt; está activo.n";
push(@reportlist,"$host -> está activo.");
}else{
#print "$host -&amp;amp;gt; está offlinen";
push(@reportlist,"$host -> está offline.");
}
$ping->close();
}
#Reporte da lista
foreach (@reportlist)
{
print "$_n";
}
#para um ficheiro a ser enviado por mail
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