#!/bin/sh
# the next line restarts using scotty -*- tcl -*- \
exec scotty2.1.11 "$0" "$@"

package require Tnm 2.1

##
## Check the argument. If it is an IP address, lookup the hostname, 
## else lookup the address.
##

foreach arg $argv {
    if {[regexp {^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$} $arg]} {
	set code [catch {netdb hosts name $arg} res]
	if $code {
	    set code [catch {dns name $arg} res]
	}
    } else {
	set code [catch {netdb hosts address $arg} res]
	if $code {
	    set code [catch {dns address $arg} res]
	}
    }
    if $code {
	set res "<lookup failed>"
    }
    if {[regexp {^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$} $arg]} {
	puts [format "%-16s %s" $arg $res]
    } else {
	puts [format "%-16s %s" $res $arg]
    }
}

exit
