Created
November 28, 2012 16:17
-
-
Save mshock/4162289 to your computer and use it in GitHub Desktop.
Perl test host port connectivity
This file contains 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
#! perl -w | |
# test ports 80 and 1433 on given IP | |
# HTTP and SQL | |
# for new NAT addresses | |
use strict; | |
use IO::Socket::PortState qw(check_ports); | |
my $timeout = 10; | |
my %ports = ( | |
tcp => { | |
80 => {}, | |
1433 => {}, | |
} | |
); | |
open(HOSTS, '<', $ARGV[0] || '/etc/hosts'); | |
my @ips = <HOSTS>; | |
close HOSTS; | |
for my $ip (@ips) { | |
chomp $ip; | |
my $host_hr = check_ports($ip, $timeout, \%ports); | |
for my $port (sort {$a <=> $b} keys %{$host_hr->{tcp}}) { | |
my $stat = $host_hr->{tcp}{$port}{open} ? 'success' : 'failure'; | |
print "$ip - $port - $stat\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment