1 #!/usr/bin/perl -w 2 3 # $Id:$ 4 5 # check to see if server is listening on a tcp port 6 7 use strict; 8 use IO::Socket; 9 10 my @servers = qw(localhost); 11 12 my %ports = ( 13 telnet => "23", 14 smtp => "25", 15 pop3 => "110", 16 named => "53", 17 http => "80", 18 https => "443", 19 ); 20 21 my $proto = "tcp"; 22 my $disco = 0; 23 24 for my $host(@servers) { 25 26 my $ip = gethostbyname($host); 27 my $ip_addr = inet_ntoa($ip); 28 29 for my $service(keys %ports) { 30 31 my $disco = 0; 32 33 my $checkport = IO::Socket::INET->new( 34 PeerAddr => "$ip_addr", 35 PeerPort => "$ports{$service}", 36 Proto => "$proto", 37 Timeout => '0') 38 or $disco = "1"; 39 40 print "$host FAILED to repond on $service $ports{service}\n" 41 if $disco; 42 43 close $checkport; 44 45 } 46 } #### Use of uninitialized value in concatenation (.) at ./chkport.pl line 40. localhost FAILED to repond on telnet Can't use an undefined value as a symbol reference at ./chkport.pl line 43.