What is My IP Address?

Of course, we need an ad here to make it official 🙂

What about the code? Can you believe it is only one line of Perl?


Okay, I lied. You have to use the CGI module to access the remote_host() function. So the whole CGI script looks like this:


use CGI qw( :standard );

print header(), start_html(), remote_host(), end_html();

Another, more advanced usage of the function would be to write a program that can display the hops to the web server.
This requires the Net::Traceroute package (downloadable from CPAN using install Net::Traceroute)

#traceroute.pl Trace the route to the web server

use CGI qw(:standard);
use Net::Traceroute;

print header(), start_html();
$ttl = 30;
$host = remote_host();
$trace = Net::Traceroute->new(host=> "$host", max_ttl=> "$ttl");
$hops = $trace->hops;

print "

You ($host) are "; print "unreachable or more than " if ($hops = $ttl) and ($host ne $trace->hop_query_host($hops, 0)); print " $hops hops away from this page.

\n\n"; for ($i=$hops;$i>0;--$i){ $hostname = $trace->hop_query_host($i, 0); print "Unreachable" and die if $hostname eq ""; print "$hostname
\n"; } print end_html();

Leave a Reply