#!/bin/sh
#
# whose - wrapper of host, jwhois or gwhois to check addresses or names
#
# Copyright (C) 2006-2008 Taiji Yamada <taiji@aihara.co.jp>
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
WHOIS=jwhois
#WHOIS=gwhois
while [ "$1" != "" ]; do
  case "$1" in
  *[!0-9.]*)
    name="$1"
    address="`host \"$name\" | sed -ne 's/.* has address \([.0-9]*\)/\1/p'`"
    ;;
  *)
    address="$1"
    ;;
  esac
  revname="`host \"$address\" | sed -ne 's/.*domain name pointer \(.*\)./\1/p'`"
  (
  [ "$name" != "" ] &&
  echo name:	${name}
  echo revname:	${revname:-unknown}
  echo address:	${address}
  [ "$address" != "" ] &&
  $WHOIS "$address"
  ) | ${PAGER:-less}
  shift
done
