Perl code gets 127.0.0.1, not public IP Address [message #16200] |
Mon, 27 August 2007 16:59 |
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
|
|
|