SPUG: Get the local IP address?

Fred Morris m3047 at inwa.net
Wed Jul 20 14:50:54 PDT 2005

At 2:44 PM 7/20/05, Atom Powers wrote:
>I'm trying to write a script what will give me the host name ( from
>DNS ) for whatever machine it is run on. The stumbling block is
>getting the local IP address.

Hate to throw a spanner in the works, but machines can have multiple
network cards; it is unlikely that they will all have the same address. It
is also possible for a single card to be multi-homed.

OS-dependent answers include looking for a file /etc/HOSTNAME. Also, what
does hostname -i return? How does that compare to what plain old hostname
returns (do they translate to one another)? (on Linux)

That's another common problem: systems which are misconfigured. Very
common, biggest support PITA for systems which are sensitive to this sort
of issue that you can possibly imagine.

Or, how about the systems which don't even know who they are until they ask
a DNS server? Yes, they're out there (this is common on HP-UX)!

Is there a Perlish solution to this rather complex problem? Inquiring minds
want to know!


Fred Morris

More information about the spug-list mailing list