c has asked for the wisdom of the Perl Monks concerning the following question:
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 }
When I run the script, I get:
Use of uninitialized value in concatenation (.) at ./chkport.pl line 4 +0. localhost FAILED to repond on telnet Can't use an undefined value as a symbol reference at ./chkport.pl lin +e 43.
i'm staring at the print statement and the close statement. Both seem to be correct to the best that I can tell. Your input is well appreciated as always.
humbly -c
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem in IO::Socket syntax?
by Ryszard (Priest) on Mar 30, 2002 at 23:03 UTC | |
by c (Hermit) on Mar 31, 2002 at 00:13 UTC | |
by Ryszard (Priest) on Mar 31, 2002 at 00:22 UTC | |
|
Re: Problem in IO::Socket syntax?
by lestrrat (Deacon) on Mar 30, 2002 at 22:52 UTC | |
by c (Hermit) on Mar 31, 2002 at 00:16 UTC | |
by lestrrat (Deacon) on Mar 31, 2002 at 01:22 UTC | |
|
Re: Problem in IO::Socket syntax?
by flocto (Pilgrim) on Mar 31, 2002 at 00:54 UTC | |
by tye (Sage) on Mar 31, 2002 at 06:59 UTC | |
|
Re: Problem in IO::Socket syntax?
by DigitalKitty (Parson) on Mar 31, 2002 at 18:13 UTC |