Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Testing for port connectivity

by JSchmitz (Canon)
on Sep 04, 2006 at 12:20 UTC ( #571070=note: print w/replies, xml ) Need Help??

in reply to Testing for port connectivity

I think you mean open (IN, "<hostnames.txt" ) || die "Can't open hostnames.txt";

Try something more like this?

#!/usr/bin/perl -w use strict; use IO::Socket::PortState qw(check_ports); my $proto = 'tcp'; my $port = '23'; my $service = 'telnet port'; my $address = ''; my $porthash{$proto}->{$port}->{'name'} = $section; check_ports( $address, $ping_timeout, \%porthash ); my $open = $porthash{$proto}->{$port}->{'open'}; if ($open) { print "alive\n"; } else { print "dead\n"; }

Cheers -