in reply to Ping and Tracert

Net::Ping kind of sucks - see all the posts on this site about it.

I would suggest using the system ping command and parse the results. Something like (on my slack box):
my @res = `ping -c 3 $ip`; if (pop @res =~ /(\d+\.\d+)\/(\d+\.\d+)\/(\d+\.\d+)) { my @sorted = sort ($1,$2,$3); print pop @sorted }
Update: just for kicks, here's the above golfed down a bit :-)
print(((sort(((`ping -c3 $ip`)[-1])=~/(\d+\.\d+)\/(\d+\.\d+)\/(\d+\.\d ++)/))[-1]) )
Also - regarding your question re: multiple OS's. That's the problem with non-modular code. Anyways, what I would suggest is that you set the command you will run earlier in the script depending on the os (ie $ping = "command" if $^O =~ /Solaris/ etc..

Replies are listed 'Best First'.
Re: Re: Ping and Tracert
by qball (Beadle) on Aug 31, 2001 at 22:20 UTC
    -c 3 doesn't work on Solaris. Any suggestions as to how I can write the script to be usable on both Solaris and Linux platforms?

    Thanks.

    qball~"I have node idea?!"

      You get the OS name in $^O so all you need to do is (pseudocode)

      print "The OS is $^O"; if ( $^O =~ /Linux/ ) { &linux_ping; } elsif ( $^O =~ /Solaris/ ) { &sun_ping; } else { die "Get a real OS!\n"; }

      I don't know what $^O holds on Solaris so you will have to tweak the matches to suit.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        Ok, I can ping Linux X number of times using -c, but Solaris? What's the param for that. I've been searching through the man pages and can't find it.

        Thanks.

        qball~"I have node idea?!"