Excellent stuff tye. I just thought I'd something
which might help.
You can use connect with UDP sockets - its just
an API thing though and it sets the 'default address' to
which packets are sent, as well as filtering packets to
only be received from that address. That's not very
useful, but what is more useful is that you can
detect the 'port unreachable' ICMP messages that would
be sent back through the normal API. The error ICMP packets
which the ip stack receives are associated with the socket
and so if you try and send another packet after one of these
error packets has been received, you get an error back from
the send (although the packet is still sent I think).
So, if you know that the host isn't listening on a particular
UDP port, then a simple UDP ping can be done without
needing any special permissions.
Anyway, try this - it works for me!
#! /usr/bin/perl -w
use strict;
use IO::Socket::INET;
my($host, $port) = qw(localhost 12345);
my $sock = IO::Socket::INET->new(PeerAddr => $host,
PeerPort => $port,
Proto => 'udp') || die;
my $retry = 6;
while ($retry--) {
unless (send($sock, "ping!", 0)) {
print "Host is up? ($!)\n";
}
sleep(1);
}
Have fun,
rdw
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, 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, 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.
|
|