#!/bin/sh
# @(#) $Id: arpfetch,v 1.4 2000/03/21 02:27:45 leres Exp $ (LBL)
#
# arpfetch - collect arp data from a cisco using snmpwalk
#
if test $# -ne 2; then
	echo "usage: $0 host cname"
	exit 1
fi
#
host=$1
cname=$2
temp=/tmp/arpfetch.temp.$$
errs=/tmp/arpfetch.errs.$$
what="ip.ipnettomediatable.ipnettomediaentry.ipnettomediaphysaddress"
#
# Get the data
#
snmpwalk -v 1 $host $cname $what | 2>&1 tr A-Z a-z > $temp
#
# Try to make up for the fact that snmpwalk doesn't write errors to stderr
#
grep -v $what $temp > $errs
if test -s $errs; then
	cat $errs 1>&2
	rm -f $temp $errs
	exit 1
fi
#
# Convert the results
#
sed -e 's/[ 	][ 	]*/ /g' \
    -e 's/ = hex: /=/' \
    -e 's/ $//' \
    -e 's/ /:/g' \
    -e 's/^.*\.\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)=\(.*\)/\2	\1/' \
    -e 's/:0/:/g' \
    -e 's/^0//' $temp
#
rm -f $temp $errs
