-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsnmp-mac-port
executable file
·48 lines (39 loc) · 1.32 KB
/
snmp-mac-port
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash -e
. ./snmp.conf # get COMMUNITY
log=/dev/shm/snmp-mac-port
test -d $log || mkdir $log
#test -e /dev/shm/.git || ln -s /home/dpavlin/dell-switch/snmp-mac-port-git /dev/shm/.git
snmp_walk() {
ip=$1
if ! fping $ip 2>>/dev/shm/dead ; then
echo "ERROR: $ip"
return
fi
# Q-BRIDGE-MIB dot1qFdbTable
#snmpbulkwalk -O0sUX -v2c -Cc -c $COMMUNITY $ip 1.3.6.1.2.1.17.7.1.2.2.1.2 | sed -e 's/.*7\.1\.2\.2\.[0-9]\.[0-9]\.//' -e 's/ = [^:]*: / /' -e 's/\./ /g' | awk -v name=$ip '{ printf "%s %d %02x:%02x:%02x:%02x:%02x:%02x %d\n", name, $1, $2,$3,$4,$5,$6,$7, $8 }' | tee $log/$ip
snmpbulkwalk -O0sUX -v2c -Cc -c $COMMUNITY $ip dot1qTpFdbPort | tr '[' ' ' | tr -d ']' | awk -v name=$ip '{ printf "%s %d %s %d\n",name,$2,$4,$7 }' | tee $log/$ip
num=`cat $log/$ip | wc -l`
if [ $num -le 1 ] ; then
# fake vlan using only BRIDGE-MIB::dot1dTpFdbPort
snmpwalk -O0sUX -v2c -Cc -c $COMMUNITY $ip BRIDGE-MIB::dot1dTpFdbPort | sed -e "s/^[^:]*:/$ip -/" -e 's/\].*: / /' | tee -a $log/$ip
fi
}
if [ ! -z "$1" ] ; then
while [ ! -z "$1" ] ; do
snmp_walk $1
shift
done
exit 0
fi
#( ls -d $log.last/* | sed 's/^.*\///' ; ./ips ) | sort -u | while read ip
if [ ! -z "$1" ] ; then
snmp_walk $1
fi
# fetch all switches in parallel
./sw-names | parallel -j 70 $0
exit 0
./sw-names | while read ip
do
echo "## $ip"
snmp_walk $ip
done