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

Re: How to get an IP address



> Hi, 
> 
> I know how to get an IP address *info* using dig, but has anyone looked
> into how to get *only* the IP address? so that I can use, eg.
> 
>  the_ip=`get_ip host`

Hi Tong,

Kind people have already suggested dig and host, but may I make
another suggestion:

   getent hosts $hostname | awk '{print $1}'

It appears that host and dig only look at DNS, whereas you may be
using other name resolution methods e.g. a hosts file. "getent hosts"
takes account of that.

Also, getent is always installed (as far as I can tell), whereas host
and dig may not be installed.

I hope this helps.

-- 
Cheers,
Clive


Reply to: