Walt Mankowski on Wed, 27 Aug 2003 07:43:04 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] finding the IP


On Tue, Aug 26, 2003 at 08:49:26AM -0400, eric@lucii.org wrote:
> Anyone know how to reliably determine the IP address of a box that's
> using PPPOE?

From perlfaq9:

  How do I find out my hostname/domainname/IP address?

  The normal way to find your own hostname is to call the `hostname` pro-
  gram.  While sometimes expedient, this has some problems, such as not
  knowing whether you've got the canonical name or not.  It's one of
  those tradeoffs of convenience versus portability.

  The Sys::Hostname module (part of the standard perl distribution) will
  give you the hostname after which you can find out the IP address
  (assuming you have working DNS) with a gethostbyname() call.

      use Socket;
      use Sys::Hostname;
      my $host = hostname();
      my $addr = inet_ntoa(scalar gethostbyname($host || 'localhost'));

  Probably the simplest way to learn your DNS domain name is to grok it
  out of /etc/resolv.conf, at least under Unix.  Of course, this assumes
  several things about your resolv.conf configuration, including that it
  exists.

  (We still need a good DNS domain name-learning method for non-Unix sys-
  tems.)

Attachment: pgp3NTmiAetDj.pgp
Description: PGP signature