#!/bin/bash 
# Copyright 2002 Stephen Samuel.
# May be copied under the terms of the Gnu Public License
# 
# This script is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# or check at www.gnu.org.


# Set the ethernet address and netmask to scan for.
# If the netmask is empty, then it will be gotten from the ethernet card (ifconfig)
# to scan for only your machine, set the netmask to 255.255.255.255
# $Header: /usr/local/sbin/RCS/nimhunt,v 2.3 2002/03/28 20:09:04 samuel Exp samuel $
# $Log: nimhunt,v $
# Revision 2.3  2002/03/28 20:09:04  samuel
# changed to automagically get the IP address from your ethernet card.
#


ETHERCARD=eth0
NETMASK=''

# (for my box only)
# NETMASK='255.255.255.255'
if
  NETMASK=${NETMASK:-`ifconfig $ETHERCARD | grep inet | sed  -n 's/^.*Mask:[ ]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | egrep '[0-9]+\.[0-9]+\.[0-9]+' `} && 
  NETADDR=`ifconfig $ETHERCARD | grep inet | sed  -n 's/^[^:]*:[ ]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | egrep '[0-9]+\.[0-9]+\.[0-9]+' `  &&
ipcalc --network $NETADDR $NETMASK && 
eval `ipcalc --network $NETADDR $NETMASK`

then
	#If you want to ignore your ethernet address, then just set NETWORK here...
	# NETWORK=override.my.IP.addr.net
	export PATH=$PATH:/home/samuel/bin
	(   echo ============ 
	 tcpdump -l -tt -i eth0 -n -p 'tcp[13] & 2 !=0 ' and  dst net $NETWORK  mask $NETMASK ) | /usr/local/sbin/nimhunt.pl  `mktemp -u /tmp/nimhunt.XXXXXX` 
else
	echo netmask $NETMASK netadd $NETADDR
	echo "Nimhunt could not determine a network address."
	exit 2
fi
