in reply to Finding your IP address with Perl

The Cookbook suggests Sys::Hostname then gethostbyname (or the POSIX module's uname()):
use Sys::Hostname; my $hostname = hostname(); my $ip = gethostbyname($hostname);
(Untested, but pretty much verbatim from the book.)

The POSIX::uname() method looks like:

use POSIX qw( uname ); my $hostname = (uname())[1]; # the rest as above
On systems that don't implement any part of POSIX, you'll have ... other... results. You might also try reverse resolving any IP address you get with gethostbyaddr.

Replies are listed 'Best First'.
Re: Re: Finding your IP address with Perl
by $ENV{REMOTE_USER} (Novice) on Dec 04, 2000 at 21:50 UTC
    Sys::Hostname (on linux) never seems to give me the DNS name I was assigned by the DNS server so the gethostbyname() call won't work. It does seem to work on win32 though.
      DNS name I was assigned by the DNS server

      err... assigned by the DHCP server..