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

Re: Getting hostname



On 04-May-03, 12:34 (CDT), Holger Kubiak <debian@holger-kubiak.de> wrote: 
> Hello,
> 
> I want to package a tool. In a shell-script I need access to a hostname
> belonging to a given IP. If the package host is installed I get:
> 
> holger@myhost:~$ host 193.99.144.71
> Name: www.heise.de
> Address: 193.99.144.71
> 
> If the package bind9-host is installed I get:
> 
> holger@myhost:~$ host 193.99.144.71
> 71.144.99.193.in-addr.arpa domain name pointer www.heise.de.

#!/bin/sh
foo=`host $1 | head -1 |grep -v 'NXDOMAIN'| sed 's/.* \([~ ]*\)/\1/' | sed 's/\.$//'`
if [ -n "$foo" ] ; then
    echo "hostname is $foo"
else
    echo "Reverse lookup failed for $1."
fi

If you can live with the trailing '.', you can leave off the final 'sed'
command.


Steve
-- 
Steve Greenland
    The irony is that Bill Gates claims to be making a stable operating
    system and Linus Torvalds claims to be trying to take over the
    world.       -- seen on the net



Reply to: