Let's see what ol' perldoc has to say about the matter ...
shell> perldoc -q 'ip address'
Found in /usr/lib/perl5/5.6.1/pod/perlfaq9.pod
How do I find out my hostname/domainname/IP address?
The normal way to find your own hostname is to call the
"`hostname`" program. 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 dis-
tribution) 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 systems.)
Well, there you have it :)
HTH
_________ broquaint
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|