[lug] Converting IPs to Domain Names and Vice Versa via Bash

David Morris lists at morris-clan.net
Wed Jan 26 16:44:34 MST 2005


On Wed, Jan 26, 2005 at 05:08:14PM -0700, Bill Thoen wrote:
> Does anyone know if there's a simple bash command that can
> take a domain name as input and spit out its IP? Also, can
> I go the other way?

If the system isn't too old try the 'host' command and pipe
the result through awk or sed to extract the information you
need.  On an older system try nslookup, but there is a lot
more information to filter out.

As an example:

    export IP=`host $1 | awk '{print $4}'`

--David




More information about the LUG mailing list