Script to do email nslookups

Kent Landfield kent at ssbell.UUCP
Mon Nov 27 17:52:01 AEST 1989


CSNET provides a nameserver record lookup service for the non-internet 
community. The following script (nslookup.sh) allows you to mail internet 
nameserver requests to nslookup at sh.cs.net and get back a mail message 
containing all nameserver records for the named domains.  I wrote this 
script to make it easier for our users to be able to do lookups.
I hope others find it useful as well...

For additional assistance with the CSNET email nameserver lookup service, 
please contact cic at sh.cs.net.

			-Kent+
----
Kent Landfield               UUCP:     kent at ssbell
Sterling Software FSG/IMD    INTERNET: kent at ssbell.uu.net
1404 Ft. Crook Rd. South     Phone:    (402) 291-8300 
Bellevue, NE. 68005-2969     FAX:      (402) 291-4362


# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by kent on Mon Nov 27 00:41:18 CST 1989
# Contents:  nslookup.sh
 
echo x - nslookup.sh
sed 's/^@//' > "nslookup.sh" <<'@//E*O*F nslookup.sh//'
#!/bin/sh
#
#    nslookup.sh
#
#    usage: nslookup.sh [-v] [ domain-name | IP-Address ]
#
#    options:
#        -v This option is only used in interactive mode
#           for displaying a little information about the
#           service supplied by CSNET.
#
#        This script allows Internet nameserver lookups
#        via mail requests. Nslookup.sh allows the user
#        to specify either domain names or IP Addresses
#        on the command line or with no arguments, will
#        prompt the user for the requested information.
#
#    History:
#        Created Sat Nov 25 10:09:12 CST 1989
#        By Kent Landfield (kent at ssbell.uu.net)
#
trap "" 1 2 3 

CAT=/bin/cat                  # Actual disk location
ECHO=/bin/echo                # echo command to use
RM=/bin/rm                    # Actual disk location
SED=/bin/sed                  # Actual disk location
SHELL=/bin/sh                 # Shell to use

#
# Chose the mailer of your dreams..
#    If you add one that does no support "-s subject" options
#    remove the "-s nslookup" from the MAIL_CMD declaration
#
#MAIL=/usr/ucb/Mail           # Mailer to use to send request
#MAIL=/usr/local/bin/elm      # Mailer to use to send request
MAIL=/usr/local/bin/mush      # Mailer to use to send request

#
# For BSD Based system whose echo command does not support 
# the \c formating characteristics...
# FMTCHAR=""                # no format character capabilities
# NONL=-n                   # BSD's echo "no newline" flag
#
# For System V type echo commands capable of supporting 
# the \c formating characteristics...
FMTCHAR="\c"                # format character for SYSV no-newline
NONL=                       # echo's no newline flag not needed in SYSV

#NSLOOKUP=your-account-here     # comment the real site for testing...
NSLOOKUP=nslookup at sh.cs.net   

MAIL_CMD="$MAIL -s nslookup $NSLOOKUP"

request_list=""
verbose=0

#
#    Separate the options from the requested domains (if needed)
#
for i in $@
do
    case $i in
        -v) verbose=1;;
         *) request_list="$request_list $i";;
    esac
done

#
#    If the user specified Domain name/IP addresses on the
#    command line then just build up the mail request and send it.
#
if [ "$request_list" != "" ]
then
    for i in $request_list
    do
        echo $i 
    done | $MAIL_CMD 
    exit 0
fi 

tmpfile=/tmp/nslook$$
info=$verbose

while true
do
    #
    # If they want an explaination, give it to them..
    #
    if [ $info -eq 1 ]
    then
        echo
        echo "CSNET provides nameserver record lookup services for the"
        echo "non-internet community.  $0 allows you to mail"
        echo "internet nameserver requests to \"nslookup at sh.cs.net\""
        echo "and get back a mail message containing all nameserver"
        echo "records for the named domains. Send only domain names"
        echo "or IP addresses, one per line."
        echo
        echo "For additional assistance with this CSNET service,"
        echo "contact cic at sh.cs.net."
        echo
        info=0
    fi

    echo $NONL "Domain name or IP Address (a/i/q/!/?) -> $FMTCHAR"
    read ans
    case "$ans" in
        !) 
            $SHELL
            ;;
        !*) 
            `echo $ans | $SED "s/!//"` 
            ;;
        "?"|help) 
            echo
            echo "$0 commands: "
            echo "   a, abort - Terminate $0 and send *NO* requests"
            echo "   ?, help  - this message"
            echo "   i, info  - services description message"
            echo "   q, quit  - Terminate $0 and mail requests"
            echo "   !        - execute $SHELL"
            echo "   !cmd     - execute specified cmd"
            echo "   Domain name - Send an Internet domain lookup request"
            echo "   IP Address  - Send an Internet domain lookup request"
            echo
            ;;
        a|abort) 
            echo "Aborting $0, no requests sent..."
            $RM -f $tmpfile
            exit 1
            ;;
        q|quit) 
            break 
            ;;
        i|info*)
            info=1
            ;;
        *)  
            if [ "$ans" != "" ]
            then
                echo $NONL "Send Request for $ans ? (y/n) -> $FMTCHAR"
                read doit
                if [ "$doit" = "y" ] 
                then
                    echo $ans >> $tmpfile
                else
                    echo "Skipping request for $ans"
                fi
            fi
            ;;
    esac
done

if [ -f "$tmpfile" ]
then
    if [ $verbose -eq 1 ]
    then
        echo "Sending nslookup requests for .."
        $CAT $tmpfile
    fi
    $CAT $tmpfile | $MAIL_CMD
    if [ $? -eq 0 ]
    then
        echo "nslookup mail request queued."
    else
        echo "Trouble! No request mailed."
    fi
fi
$RM -f $tmpfile
@//E*O*F nslookup.sh//
chmod u=rwx,g=rx,o=rx nslookup.sh
 
echo Inspecting for damage in transit...
temp=/tmp/shar$$; dtemp=/tmp/.shar$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\!!!
    170    641   4804 nslookup.sh
!!!
wc  nslookup.sh | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
if [ -s $dtemp ]
then echo "Ouch [diff of wc output]:" ; cat $dtemp
else echo "No problems found."
fi
exit 0



More information about the Alt.sources mailing list