Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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


In reply to Re: Net::Ping the mini series (UDP Pings) by rdw
in thread Net::Ping, the mini series by tye

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2014-09-01 19:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (15 votes), past polls