#!/bin/sh # # This script is to find all current cluster id's in use on a LAN segment. # This script must be run as root. # # Todd Mortensen # May 6 2002 device="hme0" # Device to use (hme?,le?,qe?,qfe?,etc...) count="50" # Number of packets to capture. sap="0xcafe" # Change if needed. tmpf="/tmp/fndclid" # Location of tmpfile. ibase="16" # octal progname=$0 usage() { echo "Usage: $progname [-d interface ] [-s SAP] [-c count] [ -T filename] " echo "-d Network Interface to use." echo "-s Set LLT SAP" echo "-c Number of packets to sample." echo "-T Set Temp file prefix to use." echo "-h Usage help" exit 0 } while getopts "d:s:T:c:h" opt; do case $opt in d ) device=$OPTARG ;; s ) sap=$OPTARG ;; T ) tmpf=$OPTARG ;; c ) count=$OPTARG ;; h ) usage ;; \?) usage ;; esac done # Main Script section if [ `id | cut -c5` -ne 0 ]; then echo "You must have super user (root) privileges." >&2 exit 1 fi if [ -d $tmpf ]; then echo "Sorry, -T must be followed by a temporary filename not a directory." exit 0 fi rm -f $tmpf.tmp $tmpf.out $tmpf.cap echo -n "Counting $count Heartbeats " snoop -o $tmpf.cap -c $count -d $device ethertype $sap snoop -i $tmpf.cap -x 16,6 | grep -v CAFE | sort -n | uniq | awk ' { print substr($2,1,2) ":" substr($4,3,2) } ' > $tmpf.tmp for i in `cat $tmpf.tmp|grep -v "^:"` ; do clid=`echo "$i" | awk -F: ' { print $1 } '` ndid=`echo "$i" | awk -F: ' { print $2 } '` uppercaseclid=`echo "$clid" | sed -e 's:^0[bBxX]::' | tr '[a-f]' '[A-F]'` decimalclid=`echo "ibase=$ibase; $uppercaseclid" | bc` uppercasendid=`echo "$ndid" | sed -e 's:^0[bBxX]::' | tr '[a-f]' '[A-F]'` decimalndid=`echo "ibase=$ibase; $uppercasendid" | bc` echo "$decimalclid $decimalndid" >> $tmpf.out done echo " " echo "Cluster and Node ID's detected." echo "-------------------------------" cat $tmpf.out | sort -n | uniq rm -f $tmpf.tmp $tmpf.out $tmpf.cap