Article View: comp.sys.sgi.admin
Article #10Re: system names from IP
From: Sam Fulcomer
Date: Tue, 15 Dec 1992 02:49
Date: Tue, 15 Dec 1992 02:49
94 lines
2467 bytes
2467 bytes
In article <tk0qf9s@sgi.sgi.com> arc@xingping.esd.sgi.com (Andrew Cherenson) writes:
>>
>>That is, you don't need the shell-game to reverse the address and add
>>"in-addr.arpa".
>
>nslookup takes command-line options. For example,
>
some do, some don't. This is what I use now (I fancied up the other
script to use as an example sh script for our users)...
#!/bin/sh
# if you want this to run under ultrix change to "#!/bin/sh5" (bleechh...)
###################### VARIABLES
TRUE=0
FALSE=1
VERBOSE=$FALSE
###################### ROUTINES
# remember to pass all arguments
lookit_up() {
revaddr=`echo $1 | awk -F. '{printf("%s.%s.%s.%s\n",$4,$3,$2,$1)}' `
nslookup <<%% | grep ${revaddr}.in-addr.arpa | awk '{print $NF}'
set query=ptr
${revaddr}.in-addr.arpa
%%
}
print_hostname() {
if test $VERBOSE -eq $TRUE
then
echo $1 = `lookit_up $1 `
else
lookit_up $1
fi
}
printusage() { # $0 is still the script name...
cat <<%%
usage: $0 [ -v ] [address...]
$0 looks up a hostname for each address specified,
or with no arguments, reads standard input for addresses until EOF.
-v Display result as "address = hostname"
%%
}
main() { # this is here cuz sh doesn't "goto"
if test "$#" -eq 0 # input is stdin
then
while read i
do
print_hostname $i
done
else # cmd line args...
case "$1" in
-h)
printusage >&2 # to stderr
exit
;;
-v)
VERBOSE=$TRUE
shift
main $* # we'd like "goto" here...
exit
;;
*)
;;
esac
while test $# -ge 1
do
print_hostname $1
shift
done
fi
}
### do the work
main $*
# There are a number of ways achieving the result of the
# recursion, however I'd prefer the non-exisitent "goto",
# so recursion seems the suitably perverse alternative.
--
_/**/Sam_Fulcomer sgf@cfm.brown.edu What, me panic: uba crazy
Brown University Center for Fluid Mechanics, Turbulence and Computation
Technical Details
Message-ID:
<1992Dec15.024916.7190@cs.brown.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!brunix!sgfReferences:
<tk0qf9s@sgi.sgi.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.sgi.admin Path: arc1-ca.pugleaf.net!sparky!uunet!brunix!sgf From: sgf@cfm.brown.edu (Sam Fulcomer) Subject: Re: system names from IP Message-ID: <1992Dec15.024916.7190@cs.brown.edu> Sender: sgf@cfm.brown.edu Organization: Brown University Center for Fluid Mechanics References: <tk0qf9s@sgi.sgi.com> Date: Tue, 15 Dec 1992 02:49:16 GMT Lines: 94