Last active
October 2, 2015 18:08
-
-
Save rubemlrm/2292206 to your computer and use it in GitHub Desktop.
Check Network machines
This file contains hidden or 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 | |
| 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;gt; está activo.n"; | |
| push(@reportlist,"$host -> está activo."); | |
| }else{ | |
| #print "$host -&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