use Socket; use Sys::Hostname; my $hostname = hostname(); my $name ='yahoo.com'; my $ip = inet_ntoa(scalar(gethostbyname($name)) || 'localhost'); my $myip = inet_ntoa(scalar(gethostbyname($hostname))); print $ip, "\n", $myip; __END__ sample output: 216.115.108.245 4.52.23.253