#!/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__