#!/bin/sh - ############################################################## # whoiss, wrapper for jwhois # # Performs lookups for any number of domains, netblocks, handles, IPs, ... # on a single command line, without specifying TLD servers. # # Available From: # http://www.roble.com/docs/whoiss # Thanks To: # Troy Bowman, Kare Presttun, and Tom Coradeschi for their contributions. # See Also: # # # No Thanks To: # Network Solutions (as Verisign) for originally corrupting the root whois servers. # # # # # ## This script inspired jwhois, and now extends it. www.gnu.org/software/jwhois ############################################################## # $Id: whoiss,v 1.104 2010/11/14 18:56:31 marquis Exp $ ############################################################## set -a WHOIS_CMD="jwhois -f" #WHOIS_CMD="jwhois -n" ## blackhole whois server detection logic TBD ## use a file viewer (default=less) for more than $PAGEQUERIES queries PAGEQUERIES=0 PATH=/usr/local/bin:/bin:/opt/sfw/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb _POSIX2_VERSION=199209 LANG=C barheader () { echo "==========[ $1 ]================================================================" | \ awk -F"\/\/" '{ printf "%-.75s", $1 }' 2>/dev/null } run_query () { barheader "$1" echo "" ##### using jwhois as of v1.87 ##### # $WHOIS_CMD -h $whois $1 $WHOIS_CMD $1 if [ "$APPENDABUSENERCONTACT" = "y" ]; then echo "" barheader "abuse.net contact for $1" echo "" $WHOIS_CMD -h whois.abuse.net $1 fi } if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then echo " USAGE: `basename $0` [domain[ip]] [name@domain] [ip:port#] [...]" exit 0 fi BINARY=`echo $WHOIS_CMD | awk '{ print $1 }'` which $BINARY >/dev/null 2>&1 if [ $? != 0 ]; then echo " ERROR: $WHOIS_CMD not found" exit fi #### main #### trap "echo ' '`basename $0` terminated;exit" 1 2 3 15 for query in `echo $* | sed -e 's/\[/ /g' -e 's/(/ /g'` ; do ## parse out invalid delimiters ## ## cleanup URLs, email addresses, port #s, ... query="`echo ${query} | sed -e 's/^.*@//' -e 's,^[HhFf][Tt]*[PpSs]*://,,' \ -e 's/^www\.//' -e 's/:.*$//' -e 's,/.*$,,'`" if [ "$query" = "." ] || [ "$query" = "" ]; then ## invalid query continue elif [ "`echo ${query} | grep '[A-Za-z]'`" = "" ]; then ## probably an ip, add trailing octet/s if missing, as required by some whois servers while [ "`echo ${query} | awk -F. '{ print $4 }'`" = "" ]; do query=`echo ${query} | sed -e 's/$/./' -e 's/\.\.*$/.0/'` if [ $? != 0 ]; then break fi done elif [ "`echo ${query} | grep \.`" = "" ]; then ## invalid host/domain name continue fi if [ "$query" = "" ]; then continue elif [ $# -gt "$PAGEQUERIES" ]; then ## define a decent output viewer if [ -x /bin/less ]; then PAGER="/bin/less -ceinx4" elif [ -x /usr/bin/less ]; then PAGER="/usr/bin/less -ceinx4" elif [ -x /usr/local/bin/less ]; then PAGER="/usr/local/bin/less -ceinx4" else PAGER=${PAGER:-more} fi run_query $query | $PAGER else ## to stdout run_query $query fi done