OpenVZ Forum


Home » General » Support » Perl code gets 127.0.0.1, not public IP Address
Perl code gets 127.0.0.1, not public IP Address [message #16200] Mon, 27 August 2007 16:59
itools is currently offline  itools
Messages: 1
Registered: March 2007
Junior Member
I use this Perl code to figure out my hostname and IP address of the machine I"m on.

#!/usr/bin/perl -w

use Sys::Hostname;
use IO::Socket;

my($hostname) = hostname();
my($address)=inet_ntoa((gethostbyname($hostname))[4]);
my($hostname_full) = gethostbyname($hostname);

This works fine on a regular Linux machine. On an OpenVZ machine, it gets the hostname ok, but comes up with 127.0.0.1 for the IP address.

Any suggestions on how to get the public IP address from within Perl.

Thanks

mark
Previous Topic: Cannot allocate memory
Next Topic: OpenVZ Hangs on PAE Kernel
Goto Forum:
  


Current Time: Mon Aug 05 06:20:25 GMT 2024

Total time taken to generate the page: 0.02977 seconds