#!/bin/bash
#
# Karsten M. Self
# Thu Jan 15 01:10:55 PST 2004
#
# Omnibus spam-related lookup list.
# Yes, this means everything that can is backgrounded.

export PATH=/usr/bin:/bin:/usr/local/bin

FQDN2DOMAIN=/home/karsten/bin/fqdn2domain

# BASH functions defined here.
. /home/karsten/bin/spam-functions


IP=$1

if [ "x$IP" = "x" ]; then
   echo "Please supply an IP.  Quitting"
   exit
fi


REVERSE_IP=$( reverse_ip $IP )

HOST=$(
    host -W 60 $IP |
	awk '/domain name pointer/ {print $5 }' |
	sed -e 's/\.$//' |
	lower
)

echo -e "IP: $IP ($HOST)"

BASE_DOM=$( echo $HOST | $FQDN2DOMAIN )

ASN_ADDRS=''
# Get ASN information:
# http://www.routeviews.org/
ASN_RESULT=( $( 
    host -t txt $( reverse_ip $IP ).asn.routeviews.org |
	sed -e 's/.* text //' -e s'/"//g' 
) )

echo
for i in $( seq 0 $(( ${#ASN_RESULT[*]}%3 )) )
do
    ASN[$i]="${ASN_RESULT[$i]}"
    ASNSTART[$i]="${ASN_RESULT[$((i+1))]}"
    ASNPREFIX[$i]="${ASN_RESULT[$((i+2))]}"

    # ASN Org
    ASN_ORG[$i]="$( 
	jwhois ${ASN[$i]} | sed -ne 's/^OrgName:[ 	]*//p' 
	)"

    echo -e "ASN ($i):  ${ASN[$i]}  - \c"
    echo "CIDR: ${ASNSTART[$i]}/${ASNPREFIX[$i]}";
    echo "ASN Org ($i):  ${ASN_ORG[$i]}"
    # Get addressees if not bogus
    if [ "${ASN[$i]}" != "4294967295" ]; then
	ASN_ADDRS="$( whoismail AS${ASN[$i]} ), $ASN_ADDRS"
    fi
done

ASN_ADDRS="$( echo $ASN_ADDRS | sed -e 's/, *$//' )"
echo -e "ASN_ADDRS: $ASN_ADDRS\n"

if [ "x$BASE_DOM" != x ]; then
    echo
    echo "Base domain: $BASE_DOM"
    host -t txt $BASE_DOM.abuse.rfc-ignorant.org
    host -t txt $BASE_DOM.postmaster.rfc-ignorant.org
    host -t txt $BASE_DOM.whois.rfc-ignorant.org
    host -t txt $BASE_DOM.bogusmx.rfc-ignorant.org
    host -t txt $BASE_DOM.contacts.abuse.net
    echo
    echo -e "\n$BASE_DOM contacts: $( whoismail $BASE_DOM )"
fi

echo -e "WHOIS (IP) contacts: $( whoismail $IP )\n"

host -t txt $REVERSE_IP.asn.routeviews.org
host -t txt $REVERSE_IP.bl.spamcop.net
host -t txt $REVERSE_IP.cbl.abuseat.org
host -t txt $REVERSE_IP.dnsbl.njabl.org
host -t txt $REVERSE_IP.dnsbl.sorbs.net
host -t txt $REVERSE_IP.l1.spews.dnsbl.sorbs.net
host -t txt $REVERSE_IP.l2.spews.dnsbl.sorbs.net
host -t txt $REVERSE_IP.ipwhois.rfc-ignorant.org
host -t txt $REVERSE_IP.list.dsbl.org
host -t txt $REVERSE_IP.multihop.dsbl.org
host -t txt $REVERSE_IP.relays.ordb.org
host -t txt $REVERSE_IP.relays.vsi.com
host -t txt $REVERSE_IP.sbl-xbl.spamhaus.org

