As previously pointed out, Net::Ping isn't the best choice for this task, but if you do use it, here are some things to bear in mind:-

If that still hasn't put you off, the following code sort of does what you want - bear in mind the caveat that the route may change between pings, and that from_ip is an undocumented property of the Net::Ping class obtained by reading the source - it's almost never a good idea to use stuff like that.

#!/usr/bin/perl use strict; use warnings; use Net::Ping; my $target_name = 'www.bbc.co.uk'; # The name doesn't always resolve to the same IP, so we pick one # and stick with it my (undef, undef, $target_ip) = Net::Ping->new("icmp") ->ping($target_name); for my $ttl (1..30){ # Only way to change the ttl is at object construction time # ALL the intermediate parameters are required; skipping or using # 'undef' doesn't work my $p = Net::Ping->new("icmp", 0.5, 0, 0, 0, $ttl); $p->ping($target_ip); # Not all pings will return a 'from_ip', so initialise it here my $from_ip = '*.*.*.*'; # If the intermediate host returned an IP, it will be in the # undocumented 'from_ip' element of the object $from_ip = join('.',unpack('C4', $p->{from_ip})) if $p->{from_ip}; print "$ttl \t $from_ip \n"; # If the 'from_ip' is the same as the target, we're done last if $from_ip eq $target_ip; } 0; __END__

In reply to Re: Simulating traceroute using the Ping module by Myrddin Wyllt
in thread Simulating traceroute using the Ping module by Xenos

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!
  • 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, details, 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, summary, 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:
    & &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.