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! | [reply] |
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--
| [reply] |
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.
| [reply] [d/l] |
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.
| [reply] |
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.
| [reply] [d/l] |
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.
| [reply] |