#!/bin/bash
#
# Perform network detection using arpfind tests
# You need to pick a machine on each network with a fixed IP address.
#
# Note that you need to be using the 'iputils-arpfind' package, rather
# than the 'arpfind' package!
#
# For each network, add an entry to the ADDRS= line in the format
#  <Hardware address>,<IP address>,<location name>
#
# You can get the hardware address by entering arping <IP address> 
# on the command line.
# Seperate each seperate location by whitespace, but don't use any
# between commas.  Example:
#ADDRS="00:00:AB:CD:AB:CD,192.168.0.1,home \
#       00:11:22:33:44:FF,10.1.2.3,office"

# Uncomment the line below and set for your network
#ADDRS=

DEVICE=${1:-"eth0"}
ARPFIND=/usr/share/whereami/arpfind

for NET in $ADDRS ; do
  hwaddr=`echo "$NET" | cut -f1 -d,`
  ipaddr=`echo "$NET" | cut -f2 -d,`
  loc=`echo "$NET" | cut -f3 -d,`

  if $ARPFIND $DEVICE $hwaddr $ipaddr ;then
        LOCATED=1
        echo $loc >> iwillbe
        break
  fi
done

