#!/bin/ksh93 # Usage: see $0 -h typeset -r VERSION='1.0' FPROG=${.sh.file} PROG=${FPROG##*/} SDIR=${FPROG%/*} function showUsage { [[ -n $1 ]] && X='-?' || X='--man' getopts -a ${PROG} "${ print ${USAGE} ; }" OPT $X } function doMain { typeset AHOST="$1" CNAME="$2" [[ -z ${AHOST} ]] && showUsage 1 && return 1 [[ -z ${CNAME} ]] && CNAME='public' typeset -l VAL typeset -A IGNORE typeset KEY X IP IDX # CISCO-VLAN-IFTABLE-RELATIONSHIP-MIB: cviRoutedVlanIfIndex='.1.3.6.1.4.1.9.9.128.1.1.1.1.3' # RFC1213-MIB: ipNetToMediaPhysAddress='.1.3.6.1.2.1.4.22.1.2' # -O # X .. display table indexes in a more "program like" output # s .. display the MIB obj name (+ any instance or other subidentifiers) # q .. remove '=' and type info snmpbulkwalk -OqsX -v 2c -c ${CNAME} ${AHOST} ${cviRoutedVlanIfIndex} | \ while read KEY VAL; do # don't wanna have the MACs of "routing" vlan switches IGNORE["@${VAL}"]=1 done snmpbulkwalk -OqsX -v 2c -c ${CNAME} ${AHOST} ${ipNetToMediaPhysAddress} | \ while read KEY VAL; do X=${KEY:24} # rm leading 'ipNetToMediaPhysAddress[' IP=${X:#*]} # rm leading "${ifIdx}]" -> "[$ip]" X="${.sh.match}" # re-use matched part IDX="@${X:0:${#X}-1}" # rm trailing ']' from IfIdx [[ -n ${IGNORE["${IDX}"]} ]] && continue print "${VAL}\t${IP:1:${#IP}-2}" done } USAGE="[-?${VERSION}"' ] [-copyright?Copyright (c) 2016 Jens Elkner. All rights reserved.] [-license?CDDL 1.0] [+NAME?'"${PROG}"' - collect arp data from a cisco machine via snmp] [+DESCRIPTION?This script is more or less a simple wrapper around \bsnmpbulkwalk\b(1), which fetches the arp tables from a cisco machine with the IP or hostname \ahost\a using SNMPv2c to get and display pairings between ip and ethernet addresses on stdout. The \apw\a is the community string to use for SNMP transactions with this machine (Default: public).] [+?This fetching of address mappings can be further automated by using a script like /var/arpwatch/bihourly .] [h:help?Print this help and exit.] [F:functions?Print a list of all functions available.] [T:trace]:[functionList?A comma separated list of functions of this script to trace (convinience for troubleshooting).] [+SEE ALSO?\bsnmpbulkwalk\b(1).] \n\n\ahost\a [\apw\a] ' TMP= ERR_DIR= EMAIL= X="${ print ${USAGE} ; }" while getopts "${X}" OPT ; do case ${OPT} in h) showUsage ; exit 0 ;; T) if [[ ${OPTARG} == 'ALL' ]]; then typeset -ft ${ typeset +f ; } else typeset -ft ${OPTARG//,/ } fi ;; F) typeset +f && exit 0 ;; *) showUsage 1 ; exit 1 ;; esac done X=$((OPTIND-1)) shift $X && OPTIND=1 unset X doMain "$@"