home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / sgi / admin / 12 < prev    next >
Encoding:
Text File  |  1992-12-14  |  2.3 KB  |  106 lines

  1. Newsgroups: comp.sys.sgi.admin
  2. Path: sparky!uunet!brunix!sgf
  3. From: sgf@cfm.brown.edu (Sam Fulcomer)
  4. Subject: Re: system names from IP
  5. Message-ID: <1992Dec15.024916.7190@cs.brown.edu>
  6. Sender: sgf@cfm.brown.edu
  7. Organization: Brown University Center for Fluid Mechanics
  8. References: <tk0qf9s@sgi.sgi.com>
  9. Date: Tue, 15 Dec 1992 02:49:16 GMT
  10. Lines: 94
  11.  
  12. In article <tk0qf9s@sgi.sgi.com> arc@xingping.esd.sgi.com (Andrew Cherenson) writes:
  13. >>
  14. >>That is, you don't need the shell-game to reverse the address and add
  15. >>"in-addr.arpa".
  16. >
  17. >nslookup takes command-line options. For example,
  18. >
  19.  
  20. some do, some don't. This is what I use now (I fancied up the other
  21. script to use as an example sh script for our users)...
  22.  
  23.  
  24. #!/bin/sh  
  25.  
  26. # if you want this to run under ultrix change to "#!/bin/sh5" (bleechh...)
  27.  
  28. ###################### VARIABLES
  29. TRUE=0
  30. FALSE=1
  31. VERBOSE=$FALSE
  32.  
  33. ###################### ROUTINES
  34.              # remember to pass all arguments
  35. lookit_up() {        
  36.     revaddr=`echo $1 | awk -F. '{printf("%s.%s.%s.%s\n",$4,$3,$2,$1)}'  `
  37.         nslookup <<%% | grep ${revaddr}.in-addr.arpa | awk '{print $NF}'
  38.         set query=ptr
  39.         ${revaddr}.in-addr.arpa
  40. %%
  41. }
  42.  
  43. print_hostname() {
  44.     if test $VERBOSE -eq $TRUE
  45.     then
  46.     echo $1 = `lookit_up $1 `
  47.     else
  48.     lookit_up $1
  49.     fi
  50. }
  51.  
  52. printusage() {                # $0 is still the script name...
  53. cat <<%%  
  54.  
  55.     usage:     $0 [ -v ] [address...]
  56.  
  57.     $0 looks up a hostname for each address specified,
  58.     or with no arguments, reads standard input for addresses until EOF.
  59.  
  60.         -v    Display result as "address = hostname"
  61. %%
  62. }
  63.  
  64. main() {                # this is here cuz sh doesn't "goto"
  65. if test "$#" -eq 0             # input is stdin    
  66. then
  67.     while read i
  68.     do
  69.     print_hostname $i
  70.     done
  71. else                    # cmd line args...
  72.     case "$1" in
  73.     -h)
  74.         printusage >&2        # to stderr
  75.         exit
  76.         ;;
  77.     -v)
  78.             VERBOSE=$TRUE
  79.             shift
  80.         main $*            # we'd like "goto" here...
  81.         exit 
  82.             ;;
  83.      *)
  84.         ;;
  85.     
  86.     esac
  87.  
  88.     while test $# -ge 1
  89.     do
  90.     print_hostname $1
  91.     shift
  92.     done
  93. fi
  94. }
  95.  
  96. ### do the work
  97.  
  98. main $*
  99.  
  100.         # There are a number of ways achieving the result of the
  101.         # recursion, however I'd prefer the non-exisitent "goto",
  102.         # so recursion seems the suitably perverse alternative.
  103. -- 
  104. _/**/Sam_Fulcomer    sgf@cfm.brown.edu    What, me panic: uba crazy
  105. Brown University  Center for Fluid Mechanics, Turbulence  and Computation
  106.