Skip to content

Instantly share code, notes, and snippets.

@mshock
Created November 28, 2012 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mshock/4162289 to your computer and use it in GitHub Desktop.
Save mshock/4162289 to your computer and use it in GitHub Desktop.
Perl test host port connectivity
#! 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