Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Module Net-Ping

by Preceptor (Chaplain)
on Sep 23, 2002 at 16:54 UTC ( #200162=note: print w/ replies, xml ) Need Help??


in reply to Module Net-Ping

At a guess, it's because you are using UDP for your ping.
If you aim a UDP packet at a 'closed' port, then you get an ICMP 'destination port unreachable' (OTOH).
It means, that it could reach the host, but the port in question wasn't open. Suggest you either try a 'known good' udp port (hard on a mailserver) or use TCP or ICMP instead.
HTH
--
It's not pessimism if there is a worse option, it's not paranoia when they are and it's not cynicism when you're right.


Comment on Re: Module Net-Ping
packet types & ports
by Kozz (Friar) on Sep 23, 2002 at 17:04 UTC
    Preceptor: Thank you for the reply. I chose "UDP" because it is the Net::Ping's default. "TCP" likewise returns unreachable.

    If I change it to 'icmp', it DOES work, but only if effective uid is root (per the module's documentation). I wanted to run this w/o root privs, just as a plain user.

    There are indeed other services available on this server, but I don't see in the Net::Ping documentation any way to specify a different port number from the default ('echo'). Perhaps the only thing I can do is run it as root or setuid the script. But any other advice would be helpful.

    Thank you!

      I'd suggest trying using netcat to test whether echo/tcp and echo/udp are actually available.
      Otherwise, you are probably looking at implementing a similar functionality using Net::Telnet (using the POP port)
      I posted a CUFP here. From which you could probably quite easily nab the 'OpenConn' sub to do what you want.
      --
      It's not pessimism if there is a worse option, it's not paranoia when they are and it's not cynicism when you're right.

      On CPan there is a Net::Ping::External that relies on the binary ping command that does not need root level permissions (I presume so long as your ping command doesn't)

      It also works on a wide variety of systems

      Check it out!

      --blm--
        Not to be too picky, but your ping command almost certainly _does_ require root permissions.
        It's because for ICMP 'echo replies' to get back to the program, it effectively has to snoop the interface - there's absolutely no state in ICMP, so it just has to listen to see if it gets something that matches.
        Of course, since it's a compiled binary that's _generally_ trusted, that's not a huge problem. Course, you could probably just do a system("ping -c 1 $host");(syntax dependant on OS) and grep for 'bytes from'.
        --
        It's not pessimism if there is a worse option, it's not paranoia when they are and it's not cynicism when you're right.
        blm: Thanks for the suggestion, btw!

        Originally I tried parsing the output directly from /bin/ping but the script spewed an error about execute permissions of ping from within the script. THAT's why I had pursued Net::Ping, though only the ICMP worked as root.

        I tried Net::Ping::External and it worked like a charm, no setuid bit or anything needed. Worked sweet. Thanks again.

      It's seems weird to be advocating another non-Perl solution in so short a timespan, but this is something done obscenely easy with a shell script if your ping binary has appropriate permissions (they usually do)...

      #!/bin/sh PING='/bin/ping -c 5' # FreeBSD/Linux #PING='/usr/sbin/ping' # Solaris FETCHMAIL='/usr/local/bin/fetchmail -s -t 60' $PING $hostname 1>/dev/null 2>&1 \ && $FETCHMAIL

      If you absolutely must write something in Perl, then I second blm's suggestion of Net::Ping::External (alt.).

          --k.


Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://200162]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (18)
As of 2015-07-01 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (6 votes), past polls