Fellow monks, I am having problems with a script I wrote. For you're ease, I'll break the query down to the following table of contents
(hopefully the anchors work, sorry if they don't):
- Task at hand
- Problems encountered
- Code
Task at hand
1. Have a set of servers to connect to and:
2. Have a list of different ports (per server)
3. Attempt to connect to each port listed under each server
4. Report attempted connect as either the port being up, or down
----
Problems encountered
The results I got back are:
Starting Ping System
Service at arbornet.org on port:
ARRAY(0x804b424) is down
Can't use an undefined value as a symbol reference at ./new_ping.pl li
+ne 47.
When I am not using warnings or strict, line 47 does not error, and when I am using a single port (80 possibly), it does not error. Mind you, I modify it so that it does not try to do the foreach loop on the ports in the latter possibility...
----
Code
#!/usr/local/bin/perl
use IO::Socket;
use strict;
use warnings;
# default port
my $pt = "8080";
my $inactive;
my $call;
my $server_ip;
my @remote_server;
my @remote_port;
$remote_server[0] = "arbornet.org";
$remote_port[0][0] = "21";
$remote_port[0][1] = "23";
$remote_port[0][2] = "80";
#$remote_server[1] = "slashdot.org";
#$remote_port[1][0] = "80";
#$remote_server[2] = "apple.com";
#$remote_port[2][0] = "80";
#$remote_server[3] = "yahoo.com";
#$remote_port[3][0] = "80";
my $i = 0;
print "Starting Ping System\n";
foreach $server_ip (@remote_server){
print "\nService at $server_ip on port:\n";
foreach $pt ($remote_port[$i]){
$inactive = 0;
$call = IO::Socket::INET-> new (
PeerAddr => "$server_ip",
PeerPort => "$pt",
Proto => 'tcp',
Timeout => '5',
) or $inactive = 1;
if (!($inactive)) {
print " $pt is up\n";
} else {
print " $pt is down\n";
}
close $call;
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.