#!/bin/bash #Copyright 2002 William Stearns #Released under the GPL. Version='0.3' if [ "$1" = "-h" ]; then echo "hostlookup version $Version" >>/dev/stderr echo " Returns the hostnames of IP addresses given on command line or stdin." >>/dev/stderr echo "Usage" >>/dev/stderr echo " hostlookup 127.0.0.1 Hostname for this address" >>/dev/stderr echo " hostlookup 127.0.0. Scan this class C" >>/dev/stderr echo " hostlookup 127.0. Scan this class B" >>/dev/stderr echo " echo 12.13.14.15 12.13.14.16 | hostlookup" >>/dev/stderr exit 1 fi CommandLine='no' dolookup () { SPLITIP=$1 I1O1=${SPLITIP%%.*} ; SPLITIP=${SPLITIP#*.} I1O2=${SPLITIP%%.*} ; SPLITIP=${SPLITIP#*.} I1O3=${SPLITIP%%.*} ; SPLITIP=${SPLITIP#*.} I1O4=$SPLITIP if [ -n "$I1O1" -a -n "$I1O2" -a -n "$I1O3" -a -n "$I1O4" ]; then #All 4 octets, single IP check ( host -t PTR "$I1O1.$I1O2.$I1O3.$I1O4" 2>/dev/null || echo 'domain name pointer ' ) | grep 'domain name pointer' | sed -e 's/.*domain name pointer //' | sed -e "s/^/$I1O1.$I1O2.$I1O3.$I1O4 /" elif [ -n "$I1O1" -a -n "$I1O2" -a -n "$I1O3" ]; then #3 octets, class C loop echo "Scanning class C $I1O1.$I1O2.$I1O3." >>/dev/stderr for Octet4 in `seq 0 255` ; do ( host -t PTR "$I1O1.$I1O2.$I1O3.$Octet4" 2>/dev/null || echo 'domain name pointer ' ) | grep 'domain name pointer' | sed -e 's/.*domain name pointer //' | sed -e "s/^/$I1O1.$I1O2.$I1O3.$Octet4 /" done elif [ -n "$I1O1" -a -n "$I1O2" ]; then #2 octets, class B loop echo "Scanning class B $I1O1.$I1O2." >>/dev/stderr for Octet3 in `seq 0 255` ; do for Octet4 in `seq 0 255` ; do ( host -t PTR "$I1O1.$I1O2.$Octet3.$Octet4" 2>/dev/null || echo 'domain name pointer ' ) | grep 'domain name pointer' | sed -e 's/.*domain name pointer //' | sed -e "s/^/$I1O1.$I1O2.$Octet3.$Octet4 /" done done elif [ -n "$I1O1" ]; then echo Won\'t scan a class A. fi } while [ -n "$1" ]; do dolookup "$1" CommandLine='yes' shift done if [ "$CommandLine" = 'no' ]; then while read IPS ; do set $IPS while [ -n "$1" ]; do dolookup "$1" shift done done fi