#!/bin/sh # # IP NameServerLookup # # Look up the host name for an IP. # Output will be IPHOSTNAME if nslookup is successful. # # Brent Chivers 2020/Nov/18 # Smarter code. 2020/Nov/20 # Improved formatting for IPs with multiple hostnames. 2022/Feb/20 # # Frequent use will be "sort IPList | uniq -c | ipnsl" 2020/Dec/29 # If there's an integer (not an IP) echo it through with a TAB and no NEWLINE. # (Output will be COUNTIP or COUNTIPHOSTNAME.) # Doesn't recognize integers more than 7 digits. Could add recognizing numbers w/ commas. for IP in `cat $*` ; do case $IP in [0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9] | [0-9][0-9][0-9][0-9][0-9] | [0-9][0-9][0-9][0-9][0-9][0-9] | [0-9][0-9][0-9][0-9][0-9][0-9][0-9] ) echo "$IP \c" ;; * ) NAME=`/usr/bin/nslookup $IP | /bin/grep 'name = ' | /bin/sed 's/.*name = / /'` echo "$IP$NAME" | /bin/sed 's/^ / /' ;; esac done