#!/bin/ksh ## ## SCRIPT NAME: prtplt_sho_dns_hosts_IPdupes_awk ## ## Where : in $FEDIR/scripts where FEDIR=/apps/nns_com/fea ## ############################################################################## ## PURPOSE: Uses 'nslookup' 'ls' command to get a sorted list of NNS hosts ## (and various non-printer & printer DNS devices) --- ## sorted by IP-address, rather than by-device-name. ## ## Then it uses 'awk' to extract only the duplicate IP addresses --- ## AND show the host-names/device-names of the duplicates. ## ## See 'prtplt_sho_dns_hosts_IPsort' for sort by-IP-address. ## See 'prtplt_sho_dns_hosts' for sort by-name. ## ## NOTE1: This utility shows devices in nns.com domain *AND* in ## prt.nns.com domain. ## ## NOTE2: Starting in mid-2000, printers started showing up in the nns.com ## domain instead of the prt.nns.com domain, as DHCP was being ## implemented to recognize printer definitions. ############################################################################## ## CALLED BY: $FEDIR/scripts/prtplt_mgr -> ## $FEDIR/tkGUIs/prtplt_lists ## ## where $FEDIR/scripts/prtplt_mgr is called by 'handytools' command, ## $FEDIR/scripts/handytools -- actually by ## $FEDIR/scripts/handytools.chestdef ## ## and also by the 'screentools' command, $FEDIR/scripts/screentools ## --- actually by $FEDIR/scripts/screentools.chestdef. ## ## May be called in a 'net-tools' or 'net-admin' toolchest someday. ## ## Can also be called user $HOME/.auxchestrc files. Example: ## /usr/people/bmo01/.auxchestrc. ## ## Could also be a desktop icon, created by 'Find, File QuickFind' on ## SGI Toolchest. ############################################################################## ## METHOD (brief summary): ## This utility re-formats and merges device-name/IP-address records from both ## the 'nns.com' and 'prt.nns.com' domains. It then sorts the ## records by IP-address. Then it reports only the devices with ## 'duplicate' IP-addresses. ############################################################################## ## MAINTENANCE HISTORY: ## Written by: Blaise Montandon 9mar2001 Based on ## 'prtplt_sho_dns_hosts_IPsort' ## in $FEDIR/scripts ## Updated by: Blaise Montandon 2apr2001 Improved the report header&trailer. ############################################################################## if test "$FEDIR" = "" then FEDIR=/apps/nns_com/fea fi ############################################################################## ## WARN USER THAT THIS QUERY WILL TAKE ABOUT 10 SECONDS. ## (I.e. the next popup will be in about 10 secs.) ############################################################################## xconfirm -c -B DISMISS \ -t "This DNS (network) devices query will take about 30 seconds" \ -t "to complete." \ -t "" \ -t "It re-formats and merges device-name/IP-address records from both" \ -t "the 'nns.com' and 'prt.nns.com' domains. It then sorts the" \ -t "records by IP-address. Then it reports only the devices with" \ -t "'duplicate' IP-addresses." \ -font -*-courier-bold-r-normal-*-14-*-*-*-*-*-*-* \ > /dev/null & # -font -adobe-courier-bold-r-normal-*-14-*-*-*-*-*-*-* \ ############################################################################## ## PREP THE NAMES OF THE LIST FILE (AND INTERMEDIATE FILES). ############################################################################## . $FEDIR/scripts/set_localoutlist # FOR 'nns.com' OUTLIST_IPunsorted=${OUTLIST}_IPunsorted OUTLIST_IPcleaned=${OUTLIST}_IPcleaned # FOR 'prt.nns.com' OUTLIST_IPunsorted2=${OUTLIST}_IPunsorted2 OUTLIST_IPcleaned2=${OUTLIST}_IPcleaned2 # FOR combined 'nns.com' & 'prt.nns.com' OUTLIST_IPsorted=${OUTLIST}_IPsorted ############################################################################## ## PREP THE TOP OF THE LIST (A HEADING). ############################################################################## echo "\ ****************** `date '+%Y %b %d %a %T%p %Z'` *************************** HOST MACHINES (& other devices, like printers and routers) on the NNS NETWORK, in the 'nns.com' domain *PLUS* the 'prt.nns.com' domain, ************************************ *** WITH DUPLICATE IP-ADDRESSES **** ************************************ -- according to NNS DNS (Domain Name Service), via the 'nslookup' command. Performed on host: `hostname` SORTED BY *IP-ADDRESS*. A description of this list is at the bottom of the list. ------------------------------------------------------------------------ " > $OUTLIST ############################################################################## ## GATHER THE LIST CONTENTS -- with nslookup. ############################################################################## ## 'man nslookup' shows: ## ## ls [option] domain [> filename] ## ls [option] domain [>> filename] ## List the information available for domain, optionally creating or ## appending to filename. The default output contains host names and ## their Internet addresses. Option can be one of the following: ## ## -t querytype ## lists all records of the specified type (see querytype below). ## ## -a lists aliases of hosts in the domain. synonym for -t CNAME. ## ## ***>> -d lists all records for the domain. synonym for -t ANY. ## ## -h lists CPU and operating system information for the domain. ## synonym for -t HINFO. ## ## -s lists well-known services of hosts in the domain. synonym for ## -t WKS. ## ## When output is directed to a file, hash marks are printed for every ## 50 records received from the server. ## AND: ## querytype=value ## type=value ## Change the type of information query to one of: ## ## A the host's Internet address. ## ## CNAME the canonical name for an alias. ## ## HINFO the host CPU and operating system type. ## ## MINFO the mailbox or mail list information. ## ## MX the mail exchanger. ## ## NS the name server for the named zone. ## ## PTR the host name if the query is an Internet address, ## otherwise the pointer to other information. ## ## SOA the domain's ``start-of-authority'' information. ## ## TXT the text information. ## ## UINFO the user information. ## ## WKS the supported well-known services. ## ## Other types (ANY, AXFR, MB, MD, MF, NULL) are described in the ## RFC-1035 document. ## (Default = A, abbreviations = q, ty) ############################################################################## ## FOR TESTING: # set -x ######################################### ## GET 'nns.com' DNS 'A' RECS. ## FOR 'PRODUCTION' (see test below). ######################################### ## NOTE: 'ENDofINPUT' must start in col1. ######################################### nslookup > $OUTLIST_IPunsorted << ENDofINPUT ls -t A nns.com exit ENDofINPUT ## FOR TESTING: # $FEDIR/scripts/shofil $OUTLIST_IPunsorted # exit ############## ## FOR TESTING: ############## # TEST_INPUT=YES TEST_INPUT=NO if test "$TEST_INPUT" = "YES" then echo "\ Default Server: netman4.nns.com Address: 172.16.4.203 > [netman4.nns.com] w 172.16.92.149 cc server = netman4.nns.com cc server = netman1.nns.com eb server = netman4.nns.com eb server = netman1.nns.com apt 205.128.202.79 apt_test 205.128.202.79 sapapp00-bp 172.16.180.10 sapapp01-bp 172.16.180.1 sapapp02-bp 172.16.180.2 sapapp03-bp 172.16.180.19 sapapp04-bp 172.16.180.4 sapapp04X-bp 172.16.180.4 sapapp05-bp 172.16.180.5 sapapp05X-bp 172.16.180.5 sapdev00-bp 172.16.180.13 sapdev01-bp 172.16.180.36 sapdev02-bp 172.16.180.15 sapdev02X-bp 172.16.180.15 " > $OUTLIST_IPunsorted fi ############################################################################## ## ONE COULD GENERATE JUST A LIST of ' A ' RECS and 'CNAME ' recs -- ## but the list would be missing the query-type indicators -- A & CNAME. ############################################################################## ## nslookup > $OUTLIST_IPunsorted << ENDofINPUT ## ls -t A nns.com ## ls -t CNAME nns.com ## exit ## ENDofINPUT ############################################################################## ############################################################################## ## EXTRACT & SORT THE 'nns.com' 'A' RECS LIST. ############################################################################## ## THE "tail +5" and/or "egrep '^ '" of the EXTRACT eliminates ## the first 4 records, like: ## ## Default Server: netman4.nns.com ## Address: 172.16.4.203 ## ## > [netman4.nns.com] ############################################################################## ## THE "awk" puts the 2nd column info, which is usually ## IP address, in the 1st column --- and device-name in 2nd. ## ADDS '.nns.com' to the device names. ############################################################################## ## THE "grep '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'" of the EXTRACT removes ## non-IP-address recs, like: ## eb server = netman4.nns.com ############################################################################## ## FOR INITIAL DEVELOPMENT: # cat $OUTLIST_IPunsorted | nl >> $OUTLIST_IPsorted ## A PRETTY DECENT WAY TO ELIMINATE TOP SEVERAL non-'A' RECS: # egrep '^ ' $OUTLIST_IPunsorted | >> $OUTLIST_IPcleaned tail +5 $OUTLIST_IPunsorted | egrep '^ ' | \ awk '{printf ("%-18s %s.nns.com\n", $2, $1)}' | \ grep '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' > $OUTLIST_IPcleaned ## FOR TESTING: # $FEDIR/scripts/shofil $OUTLIST_IPcleaned # exit ######################################### ## GET 'prt.nns.com' DNS 'A' RECS. ## FOR 'PRODUCTION' (see test below). ######################################### ## NOTE: 'ENDofINPUT' must start in col1. ######################################### nslookup > $OUTLIST_IPunsorted2 << ENDofINPUT ls -t A prt.nns.com exit ENDofINPUT ## FOR TESTING: # $FEDIR/scripts/shofil $OUTLIST_IPunsorted2 # exit ############################################################################## ## EXTRACT THE 'prt.nns.com' 'A' RECS LIST. ## ADD '.prt.nns.com' to the device names. ############################################################################## tail +5 $OUTLIST_IPunsorted2 | egrep '^ ' | \ awk '{printf ("%-18s %s.prt.nns.com\n", $2, $1)}' | \ grep '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' > $OUTLIST_IPcleaned2 ## FOR TESTING: # $FEDIR/scripts/shofil $OUTLIST_IPcleaned2 # exit ############################################################################## ##THE 'nns.com' AND 'prt.nns.com' 'A' RECS LISTS. ############################################################################## ## THE SORT sorts the four '.'-separated fields of the IP address ## numerically. ############################################################################## cat $OUTLIST_IPcleaned $OUTLIST_IPcleaned2 | \ sort -t. -k1n,1n -k2n,2n -k3n,3n -k4n,4n > $OUTLIST_IPsorted ############################################################################## ## FROM THE *IP-ADDRESS-SORTED* COMBINED LIST OF 'nns.com' & 'prt.nns.com' ## devices, ## PRINT OUT ONLY THE DUPLICATE IP-ADDRESSES, WITH THE DEVICE-NAMES ## THAT HAVE THE SAME IP-ADDRESS ON THE SAME LINE WITH THE IP ADDRESS. ## Uses an 'awk' program. ############################################################################## ## Uses 'nl' to number the duplicates. ############################################################################## cat $OUTLIST_IPsorted | awk \ 'BEGIN { ## INIT IP-COUNTS & PREV-IP & DEVICE-NAMES. IPcnt=0; prevIP=""; devNAMES=""; devLEN=24; DEBUG=0 # DEBUG=1 # end of BEGIN } { ## START OF awk-BODY (main-section) ## FOR TESTING: if (DEBUG==1) { print "" print "#DEBUG - REC-CNT="NR" inRECORD="$0 print "" } ############################################################## ## INITIALIZE THE IPcnt,prevIP,devNAMES VARS FROM THE 1st REC. ############################################################## if (NR == 1) { IPcnt=1 prevIP=$1 devNAMES=substr($2" ",1,devLEN) ## FOR TESTING: if (DEBUG==1) { print "" print "#DEBUG - IPcnt="IPcnt" prevIP="prevIP" devNAMES="devNAMES print "" } next } ###################################################################### ## IF THE IP-address of this rec DIFFERS from the address saved ## in *prevIP*, ## 1) if the *IPcnt* is greater than 1 (a duplicate/triplicate/... ## has been detected, print *prevIP* and *devNAMES*. ## 2) reset the *IPcnt* to one and re-initialize *prevIP* & *devNAMES* ## with the IP-address & devname of the current record. ###################################################################### if ( $1 != prevIP ) { if ( IPcnt > 1 ) { printf ("%-18s %s \n", prevIP, devNAMES); } IPcnt=1 prevIP=$1 devNAMES=substr($2" ",1,devLEN) next } ###################################################################### ## IF THE IP-address of this rec is the SAME as the address saved ## in *prevIP*, ## 1) increment the *IPcnt*, ## 2) concatenate the devname of the current rec onto *devNAMES*. ## (To make most of the devnames line-up in columns, pad ## the name out to *devLEN* chars. Very long names will ## be truncated to *devLEN* chars. This usually amounts ## to chopping off part of the *.com*.) ###################################################################### if ( $1 == prevIP ) { IPcnt=IPcnt + 1 newNAME=substr($2" ",1,devLEN) devNAMES=devNAMES" "newNAME ## FOR TESTING: if (DEBUG==1) { print "" print "#DEBUG - IPcnt="IPcnt" prevIP="prevIP" devNAMES="devNAMES print "" } next } ## END OF awk-BODY (main-section) } END { if ( IPcnt > 1 ) { printf ("%-18s %s \n", prevIP, devNAMES); } ## END OF awk-END (END-section) }' | nl >> $OUTLIST ## FOR TESTING: # }' ## FOR 'PRODUCTION': # }' >> $OUTLIST ## FOR TESTING: # set - ############################################################################## ## PREP THE BOTTOM OF THE LIST (A TRAILER). ############################################################################## echo " ---------------------------------------------------------------------------- INFO IN THIS LIST: This is a list of IP-addresses extracted from many thousands of network-device IP-addresses. This list identifies devices with duplicate IP addresses. (IP = Internet Protocol) ---------------------------------------------------------------------------- The device-identifiers are frequently - Unix (or MS-OS) hostnames -- including server-names, like mail-servers or web/proxy-servers -OR- - print-server box/card identifiers, -OR- - communications box names, like router names. The device-identifier may be an NNS Unix host name -- like 'iaw###' for SGI IRIX hosts and 'aix###' or 'acw###' for IBM AIX hosts. Microsoft mail-server names are currently (Jun99) of the form 'nnse#'. Note: This list was extracted from an up-to-date image from the NNS 'nns.com' & 'prt.nns.com' DNS domains -- at the time indicated in the time-stamp at the top of this list. ------------------------------------------------------------------------ PRINTERS: FOR PRINTERS, the device-identifier is often an NNS Telecomid, like H##### --- or the identifier of a print-server box to which the printer is connected, like ESI#######. Even in the case that the device-identifier is the Telecomid of the printer, the IP address is actually the IP address of a 'print server' box/card to which the printer is attached. At NNS, a Telecom ID ###### is often used to make a printer 'queue' name for SGI workstations/hosts by prefixing a building name, like B600_P###### (for Postscript print/plot files OR for HP-GL/HP-PCL/HP-PJL/HP-RTL PLOT files) and B600_T###### (used for crude text printouts; automatically adds carriage-returns, and a final form feed, to files, which are assumed to be plain text). ------------------------------------------------------------------------ DEVICE DESCRIPTIONS/LOCATIONS: This list does NOT include *descriptions/locations* of each of these devices. If you need DEVICE/HOST/PRINTER location or model information -- for example, to solve a network problem: Ask a Computer/Network Support person for help, like an SGI, or other Unix --- or MS-OS, System Administrator (of T05 'Distributed Systems' Support). (If you cannot connect to a Computer/Network Support person, you could call 8-HELP to find an appropriate contact for information on an 'nns.com' or 'prt.nns.com' device.) ------------------------------------------------------------------------ SOURCE OF THIS LIST: This list comes from the NNS DNS (Domain Name Service) via the 'nslookup' command -- applied to domains 'nns.com' & 'prt.nns.com'. In particular, this list was generated by running the script $0 on host `hostname` . ------------------------------------------------------------------------ UNDER THE COVERS: This list was assembled using the 'nslookup' command with the 'ls -t A' sub-command. Specifically, nslookup > ${OUTLIST}_IPunsorted << ENDofINPUT ls -t A nns.com exit ENDofINPUT And a similar nslookup for the 'prt.nns.com' domain, followed by an extract (filter) and a re-format and sort and numbering (with 'tail', grep', a one-line-'awk'-prog, 'sort', and finally a multi-line-'awk'-prog and 'nl'). For details, see the script $0 For information on the output of 'nslookup', you can type 'man nslookup' in an SGI winterm window. Or you can refer to the 'AnyCommand @ AnyHost' or or 'SGI TechPubs InfoSearch Web Page' options. These are available via the drawer of the NNS-SGI 'HandyTools' toolchest. ***************** END OF LIST OF DUPLICATE IP ADDRESSES ********************* ************************* (with Device Names) ******************************* ****** on the NNS NETWORK, in the 'nns.com' & 'prt.nns.com'domains ********** " >> $OUTLIST ############################################################################## ## SHOW THE LIST (IN A SCROLLABLE TEXT WINDOW). ############################################################################## $FEDIR/scripts/shofil $OUTLIST # export SHOFILENAME="$OUTLIST" # $FEDIR/tkGUIs/shofil.tk & ## FOR TESTING: # set -