最新消息:阿啰哈,本人90后,目前单身,欢迎妹子们来撩!.(。→‿←。)

通过SNMP收集交换机信息

Shell 林志斌 1019浏览

感觉这脚本是目前我所能写出的比较复杂的一个了,在项目中经过多次修改、实践、再修改……功能还是很有限,脚本略显臃肿
主要功能(适用如下厂商交换机:思科、华为、H3C、惠普,或其它):
通过交换机中开启的snmp协议来获取网络中所有交换机的信息,如:hostname、MAC address、Management vlan、Ports number、Platform,备份所有思科交换机的配置文件

Bash Shell: 通过SNMP收集交换机信息
#!/bin/bash
#Author: kashu
#Date: 2014-01-25
#Filename: snmp_info.sh
#Description: Collecting switch information via SNMP protocol.

#User has insufficent privilege.
if [ "$UID" -ne 0 ]; then
echo "Sorry,you're not root." && exit 1
#Check if the net-snmp-utils is there.
elif [ ! -x "/usr/bin/snmpwalk" -o ! -x "/usr/bin/snmpset" ]; then
echo "net-snmp-utils isn't installed." && exit 1
else :
fi

#Initialize some variables.
#############################################################
#Choose a network interface card
NIC=eth1
#Readonly snmp community string
PUB=www.kashu.org
#writable snmp community string
PRI=www.kashu.org
#snmp version
VER=2c
#If you already have a ip list file,put it here!Otherwise don't do any thing.
IP_TMP=/root/ip_scan.list
#Local machine subnet prefix
PREFIX=
#############################################################
#Local machine IP address
IP="$(ifconfig $NIC | awk '/ask/{print $2}' | cut -d: -f2)"
if [ -z "$PREFIX" ]; then PREFIX=${IP%.*}.; fi
#Define snmp agent UDP port.
PORT=161
#Some temp files.
CISCO_IP=/tmp/Cisco_ip_list.tmp
HW_IP=/tmp/HW_ip_list.tmp
H3C_IP=/tmp/H3C_ip_list.tmp
HP_IP=/tmp/HP_ip_list.tmp
OTHERS_IP=/tmp/Others_ip_list.tmp

if [ -n "$IP_TMP" ]; then
IP_TMP_EXIST=$IP_TMP
fi

if [ -z "$IP_TMP" ]; then
IP_TMP=/tmp/up_ip_list.tmp
>$IP_TMP
fi

#Create or empty the following files.
>$CISCO_IP
>$HW_IP
>$H3C_IP
>$HP_IP
>$OTHERS_IP

case "$1" in
Cis*|cis*|CIS*)    CISCO_IP="$IP_TMP" ;;
HW|hw|Huaw*|HUAW*) HW_IP=$IP_TMP ;;
h3c|H3C|h3*|H3*)   H3C_IP=$IP_TMP ;;
HP|hp|huipu)       HP_IP="$IP_TMP" ;;
Oth*|OTH*)         OTHERS_IP="$IP_TMP" ;;
esac

SORT_INFO(){
awk '/IP:/{print $2}' $SNMP_INFO | cut -d ':' -f2- | cat -n > /tmp/snmp.ip.tmp
awk -F':' '/Platform:/{print $2}' $SNMP_INFO | cat -n > /tmp/snmp.platform.tmp
awk -F':' '/Total interfaces/{print $2}' $SNMP_INFO | cat -n > /tmp/snmp.ports.tmp
awk -F':' '/Hostname:/{print $2}' $SNMP_INFO | cat -n > /tmp/snmp.hostname.tmp
awk '/MAC:/{print $3}' $SNMP_INFO | cut -d':' -f2- | cat -n > /tmp/snmp.mac.tmp
{ echo -e "33[41;37mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx33[0m" && echo "No. IP Hostname Ports MAC Platform" && join /tmp/snmp.mac.tmp /tmp/snmp.platform.tmp | join /tmp/snmp.ports.tmp - | join /tmp/snmp.hostname.tmp - | join /tmp/snmp.ip.tmp -; }| column  -t | tee ./snmp_sort.info
}

#The resulting files.
IP_LIST=~/up_ip_list.txt
SNMP_INFO=~/snmp_info_list.txt
>$SNMP_INFO
if [ "$IP_TMP" != "$IP_LIST" ]; then >$IP_LIST ; fi

SORT_IP(){
sort -unt. -k4 "$IP_TMP" >> $IP_LIST
sed -i "/$IP/d" $IP_LIST
}

PING(){
for SUFFIX in {1..254}; do
 {
   ping -i0.2 -W1 -c3 -s1 "$PREFIX$SUFFIX" &> /dev/null && echo "$PREFIX$SUFFIX" >> "$IP_TMP"
 } &
done
wait
SORT_IP
}

BASIC_SNMP(){
for I in `cat "$IP_TMP"`; do
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ifDescr|egrep -vi '(vlan|null|loop|M-)'|tee -a $SNMP_INFO|echo "Total interfaces:`wc -l`" >> $SNMP_INFO 2> /dev/null
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysDescr|sed -n '1p'|echo "Platform:`cut -d' ' -f3-`" >> $SNMP_INFO
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysName|echo "Hostname:`awk '{print $NF}'`" >> $SNMP_INFO
  INDEX_NUM="$(snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I at.atTable.atEntry.atIfIndex|grep "$I"|awk '{print $NF}')"
  echo "`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I interfaces.ifTable.ifEntry.ifDescr|grep '<Vlan'|cut -d. -f5|awk '/'"$INDEX_NUM"'/{print $NF}'` IP:$I MAC:`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ipNetToMediaPhysAddress|grep "$I"|awk '{print $NF}'`" >> $SNMP_INFO
  echo -e 'n' >> $SNMP_INFO
  wait
done
}

CISCO_SNMP(){
#Some temp files.
PEER_TMP_IP=/tmp/peer_tmp_ip.tmp
PEER_IP=/tmp/peer_ip.tmp
PEER_HOSTNAME=/tmp/peer_hostname.tmp
PEER_PLATFORM=/tmp/peer_platform.tmp
PEER_PORT=/tmp/peer_port.tmp
NATIVE_VLAN=/tmp/native_vlan.tmp
for I in `cat "$CISCO_IP"`; do
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ifDescr|egrep -vi '(vlan|null|loop|M-)'|tee -a $SNMP_INFO|echo "Total interfaces:`wc -l`" >> $SNMP_INFO 2> /dev/null
  #snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysDescr|sed -n '1p'|echo "Platform:`cut -d' ' -f3-`" >> $SNMP_INFO
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysDescr|sed -n '1p'|awk -F',' '{print $2}'|echo "Platform:`awk '{print $NF}'`" >> $SNMP_INFO
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysName|echo "Hostname:`awk '{print $NF}'`" >> $SNMP_INFO
  INDEX_NUM="$(snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex|grep "$I"|awk '/'"$I"'/{print $NF}')"
  echo "`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I interfaces.ifTable.ifEntry.ifDescr|grep ".$INDEX_NUM>"|awk '{print $NF}'` IP:$I MAC:`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ipNetToMediaPhysAddress|grep "$I"|awk '{print $NF}'`" >> $SNMP_INFO
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I 1.3.6.1.4.1.9.3.6.3|echo "Chassis SN:`awk '{print $3}'`" >> $SNMP_INFO
  #Create or empty temp files.
  >$PEER_TMP_IP
  >$PEER_IP
  >$PEER_HOSTNAME
  >$PEER_PLATFORM
  >$PEER_PORT
  >$NATIVE_VLAN
  #Collect cdp neighbors' ip address.
  R="$(snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I enterprises.9.9.23.1.2.1.1.4|cut -d'"' -f2)"
  echo "$R" | sed -n -e 's/ /./g' -n -e 's/.$//gp' >> $PEER_TMP_IP
  for i in `cat $PEER_TMP_IP`; do
    #Convert ip addresses from Hexadecimal to decimal.
    printf %d. `echo "$i" | awk 'BEGIN{FS="."}{$1="0x"$1}{$2="0x"$2}{$3="0x"$3}{$4="0x"$4}{print}'`|sed -n 's/.$//gp' >> $PEER_IP
    echo >> $PEER_IP
  done
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I enterprises.9.9.23.1.2.1.1.6|cut -d'"' -f2|tr -s ' ' '-' >> $PEER_HOSTNAME
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I enterprises.9.9.23.1.2.1.1.8|cut -d'"' -f2|awk '{print $NF}' >> $PEER_PLATFORM
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I enterprises.9.9.23.1.2.1.1.7|cut -d'"' -f2 >> $PEER_PORT
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I enterprises.9.9.23.1.2.1.1.11|awk '{print $NF="NativeVlan:"$NF}' >> $NATIVE_VLAN
  (echo "NeighborIP NeighborHostname PeerPlatform PeerPort NativeVlan" && paste $PEER_IP $PEER_HOSTNAME $PEER_PLATFORM $PEER_PORT $NATIVE_VLAN)|column -t >> $SNMP_INFO
  echo -e 'n' >> $SNMP_INFO
  #Backup running configuration files to local tftp server.
  snmpset -v $VER -c $PRI $I .1.3.6.1.4.1.9.9.96.1.1.1.1.2.50 i 1 .1.3.6.1.4.1.9.9.96.1.1.1.1.3.50 i 4 .1.3.6.1.4.1.9.9.96.1.1.1.1.4.50 i 1 .1.3.6.1.4.1.9.9.96.1.1.1.1.5.50 a "$IP" .1.3.6.1.4.1.9.9.96.1.1.1.1.6.50 s "$I.cfg" .1.3.6.1.4.1.9.9.96.1.1.1.1.14.50 i 4 > /dev/null
  snmpwalk -v $VER -c $PRI $I .1.3.6.1.4.1.9.9.96.1.1.1.1.10.50 > /dev/null
  snmpset -v $VER -c $PRI $I .1.3.6.1.4.1.9.9.96.1.1.1.1.14.50 i 6 > /dev/null
  wait
done
}

HW_SNMP(){
for I in `cat "$HW_IP"`; do
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ifDescr|egrep -vi '(vlan|null|loop|M-)'|tee -a $SNMP_INFO|echo "Total interfaces:`wc -l`" >> $SNMP_INFO 2> /dev/null
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysDescr|sed -n '2p'|echo "Platform:`cut -d' ' -f2-`" >> $SNMP_INFO
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysName|echo "Hostname:`awk '{print $NF}'`" >> $SNMP_INFO
  INDEX_NUM="$(snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I at.atTable.atEntry.atIfIndex|grep "$I"|awk '{print $NF}')"
  echo "`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I interfaces.ifTable.ifEntry.ifDescr|grep '<Vlan'|cut -d. -f5|awk '/'"$INDEX_NUM"'/{print $NF}'` IP:$I MAC:`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ipNetToMediaPhysAddress|grep "$I"|awk '{print $NF}'`" >> $SNMP_INFO
  echo -e 'n' >> $SNMP_INFO
  wait
done
}

H3C_SNMP(){
for I in `cat "$H3C_IP"`; do
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ifDescr|egrep -vi '(vlan|null|loop|M-)'|tee -a $SNMP_INFO|echo "Total interfaces:`wc -l`" >> $SNMP_INFO 2> /dev/null
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysDescr|sed -n '2p'|echo "Platform:`cut -d' ' -f2-`" >> $SNMP_INFO
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysName|echo "Hostname:`awk '{print $NF}'`" >> $SNMP_INFO
  INDEX_NUM="$(snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I at.atTable.atEntry.atIfIndex|grep "$I"|awk '{print $NF}')"
  #echo "`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I interfaces.ifTable.ifEntry.ifDescr|grep '<Vlan'|cut -d. -f5|awk '/'"$INDEX_NUM"'/{print $NF}'` IP:$I MAC:`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ipNetToMediaPhysAddress|grep "$I"|awk '{print $NF}'`" >> $SNMP_INFO
  #VIDMAC="`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ifDescr|awk -F'.' '/Vlan-interface/{print $5}'|awk '{print $1}'`"
  #MACADD="`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I interfaces.ifTable.ifEntry.ifPhysAddress|grep "$VIDMAC"|awk '{print $NF}'`"
  MACADD="`arp -n | grep -w "$I" | awk '{print $3}'`"
  echo "`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I interfaces.ifTable.ifEntry.ifDescr|grep '<Vlan'|cut -d. -f5|awk '/'"$INDEX_NUM"'/{print $NF}'` IP:$I MAC:${MACADD}" >> $SNMP_INFO
  echo -e 'n' >> $SNMP_INFO
  wait
done
}

HP_SNMP(){
for I in `cat "$HP_IP"`; do
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ifDescr|egrep -vi '(vlan|null|loop|M-)'|tee -a $SNMP_INFO|echo "Total interfaces:`wc -l`" >> $SNMP_INFO 2> /dev/null
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysDescr|sed -n '1p'|awk -F',' '{print $1}'|echo "Platform:`cut -d' ' -f3-`" >> $SNMP_INFO
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysName|echo "Hostname:`awk '{print $NF}'`" >> $SNMP_INFO
  INDEX_NUM="$(snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex|awk '/'"$I"'/{print $NF}')"
  echo "Vlan:`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I interfaces.ifTable.ifEntry.ifDescr|grep ".$INDEX_NUM>"|awk '{print $NF}'` IP:$I MAC:`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I interfaces.ifTable.ifEntry.ifPhysAddress|awk '{print $NF}'|awk 'a[$0]++'|sort -r|sed -n '1p'`" >> $SNMP_INFO
  echo -e 'n' >> $SNMP_INFO
  wait
done
}

OTHERS_SNMP(){
for I in `cat "$OTHERS_IP"`; do
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ifDescr|egrep -vi '(vlan|null|loop|M-)'|tee -a $SNMP_INFO|echo "Total interfaces:`wc -l`" >> $SNMP_INFO 2> /dev/null
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysDescr|sed -n '1p'|echo "Platform:`cut -d' ' -f3-`" >> $SNMP_INFO
  snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I sysName|echo "Hostname:`awk '{print $NF}'`" >> $SNMP_INFO
  INDEX_NUM="$(snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I at.atTable.atEntry.atIfIndex|grep "$I"|awk '{print $NF}')"
  echo "`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I interfaces.ifTable.ifEntry.ifDescr|grep '<Vlan'|cut -d. -f5|awk '/'"$INDEX_NUM"'/{print $NF}'` IP:$I MAC:`snmpwalk -Os -OQ -Ou -v $VER -c $PUB $I ipNetToMediaPhysAddress|grep "$I"|awk '{print $NF}'`" >> $SNMP_INFO
  echo -e 'n' >> $SNMP_INFO
  wait
done
}

LS_RESULT(){
if [ -n "$IP_TMP_EXIST" ]; then
 SORT_INFO
 ls -lh $SNMP_INFO $IP_TMP_EXIST ./snmp_sort.info
else
 SORT_INFO
 ls -lh $SNMP_INFO $IP_LIST ./snmp_sort.info
fi
}

CASE(){
if [ -n "$1" ]; then
  case "$1" in
  Cis*|cis*|CIS*)    CISCO_SNMP ;;
  HW|hw|Huaw*|HUAW*) HW_SNMP ;;
  h3c|H3C|h3*|H3*)   H3C_SNMP ;;
  HP|hp|huipu)       HP_SNMP ;;
  Oth*|OTH*)         BASIC_SNMP ;;
  esac
  exit
fi
}

if [ "$IP_TMP" == "/tmp/up_ip_list.tmp" ]; then
PING
fi

if [ -n "$1" ]; then
CASE
elif [ ! -x "/usr/bin/nmap" ]; then
echo "nmap isn't installed."
CASE
#If nmap does not exist on the system,then run the BASIC_SNMP.
BASIC_SNMP
LS_RESULT
exit
else
CASE
#Check nmap version.
V="$(nmap -V | awk '/version/{print $3}')"
if [ "${V%%.*}" -lt "6" ]; then echo "nmap version is too low.The results may be unreliable."; fi
if [ -z "$1" ];then
#Probe open 161 port.
for I in `cat $IP_TMP`; do
PROBE="$(nmap -sU -n -p U:$PORT $I|grep -i 'udp open ' -A1)" && CISCO="$(echo "$PROBE"|awk '/isco/{print $3}')" && HW="$(echo "$PROBE"|awk '/uawei/{print $3}')" && HP="$(echo "$PROBE"|awk '/HP/{print $3}')" && OTHERS="$(echo "$PROBE"|egrep -v '(isco|uawei|HP|snmp)'|awk '{print $3}')"
test -n "$CISCO" && echo $I >> $CISCO_IP
test -n "$HW" && echo $I >> $HW_IP
test -n "$H3C" && echo $I >> $H3C_IP
test -n "$HP" && echo $I >> $HP_IP
test -n "$OTHERS" && echo $I >> $OTHERS_IP
unset PROBE
unset CISCO
unset HW
unset H3C
unset HP
unset OTHERS
done
fi
fi

#Collect network equipments specific information.
if [ -s "$CISCO_IP" ]; then CISCO_SNMP; fi
if [ -s "$HW_IP" ]; then HW_SNMP; fi
if [ -s "$H3C_IP" ]; then H3C_SNMP; fi
if [ -s "$HP_IP" ]; then HP_SNMP; fi
if [ -s "$OTHERS_IP" ]; then OTHERS_SNMP; fi
if [ "$IP_TMP" == "/tmp/up_ip_list.tmp" ]; then
>$IP_LIST
awk '/IP:/{print $2}' $SNMP_INFO|cut -d: -f2-|sort -unt. -k4 >> $IP_LIST
sed -i "/$IP/d" $IP_LIST
fi
#Show the resulting files.
LS_RESULT
#{ echo -e "33[41;37mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx33[0m" && echo "No. MAC Hostname Ports IP Platform" && join /tmp/snmp.ip.tmp /tmp/snmp.hostname.tmp | join /tmp/snmp.platform.tmp - | join /tmp/snmp.ports.tmp - | join /tmp/snmp.mac.tmp -; } | column  -t

--------------------------------------------------------------------------------------------------------------

结果示例:

[[email protected] ~]# ./snmp_info.sh hp
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
No.  IP            Hostname          Ports  MAC                Platform
1    172.16.14.5   GUEST-CORE        48     b4:99:ba:3d:63:0   ProCurve  J8697A  Switch  5406zl
2    172.16.14.11  GUEST-10-W-1      26     28:92:4a:e1:69:20  ProCurve  J9019B  Switch  2510B-24
3    172.16.14.12  GUEST-7-E-1       52     80:c1:6e:b5:c1:80  ProCurve  j9020a  Switch  2510-48
4    172.16.14.13  GUEST-7-W-2       26     28:92:4a:e1:6a:0   ProCurve  J9019B  Switch  2510B-24
5    172.16.14.14  GUEST-7-W-1       26     28:92:4a:e1:42:40  ProCurve  J9019B  Switch  2510B-24
6    172.16.14.15  GUEST-10-W-2      26     28:92:4a:e1:b9:e0  ProCurve  J9019B  Switch  2510B-24
7    172.16.14.16  GUEST-10-E-1      52     80:c1:6e:b5:a2:c0  ProCurve  j9020a  Switch  2510-48
8    172.16.14.17  GUEST-13-E-1      52     28:92:4a:84:18:0   ProCurve  j9020a  Switch  2510-48
9    172.16.14.18  GUEST-13-W-2      26     28:92:4a:e1:ca:20  ProCurve  J9019B  Switch  2510B-24
10   172.16.14.19  GUEST-13-W-1      26     28:92:4a:e1:8a:40  ProCurve  J9019B  Switch  2510B-24
11   172.16.14.20  GUEST-16-E-1      52     80:c1:6e:b5:22:0   ProCurve  j9020a  Switch  2510-48
12   172.16.14.21  GUEST-16-W-1      26     28:92:4a:e1:6a:40  ProCurve  J9019B  Switch  2510B-24
13   172.16.14.22  GUEST-16-W-2      26     28:92:4a:e1:b5:80  ProCurve  J9019B  Switch  2510B-24
14   172.16.14.23  Gust-2F-POE-1     28     b4:39:d6:4f:ed:80  ProCurve  J9087A  Switch  2610-24-PWR
15   172.16.14.24  Gust-3F-POE-1     28     b4:39:d6:4f:7c:80  ProCurve  J9087A  Switch  2610-24-PWR
16   172.16.14.25  Gust-16F-POE-W    28     b4:39:d6:56:de:80  ProCurve  J9087A  Switch  2610-24-PWR
17   172.16.14.26  Gust-16F-POE-E    28     b4:39:d6:4f:1c:40  ProCurve  J9087A  Switch  2610-24-PWR
18   172.16.14.27  Gust-13F-POE-W    28     b4:39:d6:56:b5:c0  ProCurve  J9087A  Switch  2610-24-PWR
19   172.16.14.28  Gust-10F-POE-W    28     b4:39:d6:4f:5b:40  ProCurve  J9087A  Switch  2610-24-PWR
20   172.16.14.29  Gust-10F-POE-W-1  28     b4:39:d6:4f:6d:40  ProCurve  J9087A  Switch  2610-24-PWR
21   172.16.14.30  Gust-10F-POE-W-2  28     b4:39:d6:56:c7:0   ProCurve  J9087A  Switch  2610-24-PWR
22   172.16.14.31  Gust-3F-POE-M     28     b4:39:d6:4f:1d:80  ProCurve  J9087A  Switch  2610-24-PWR
23   172.16.14.33  3F_CR_VIP_room_1  26     28:92:4a:e1:5a:e0  ProCurve  J9019B  Switch  2510B-24
24   172.16.14.34  3F_CR_VIP_room_2  26     28:92:4a:e1:69:e0  ProCurve  J9019B  Switch  2510B-24
25   172.16.14.35  3F_CR_VIP_room_3  26     28:92:4a:e1:6a:80  ProCurve  J9019B  Switch  2510B-24
26   172.16.14.36  2F_BQT            26     28:92:4a:e1:a9:a0  ProCurve  J9019B  Switch  2510B-24
-r--r----- 1 root root  337 Aug 26 03:00 /root/shell/ip_scan.list
-rw-r--r-- 1 root root  38K Jan 25 18:53 /root/snmp_info_list.txt
-rw-r--r-- 1 root root 2.7K Jan 25 18:53 ./snmp_sort.info

[[email protected] ~]# ./snmp_info.sh h3c
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
No.  IP            Hostname   Ports  MAC                Platform
1    10.10.11.48   4F-1-2     28     74:25:8a:22:b7:f5  S3600V2-28TP-PWR-EI
2    10.10.11.49   4F-1-1     26     74:25:8a:a3:1d:22  S3100V2-26TP-EI
3    10.10.11.51   4F-2-2     28     74:25:8a:22:a0:e5  S3600V2-28TP-PWR-EI
4    10.10.11.52   4F-2-1     26     74:25:8a:a3:1e:a2  S3100V2-26TP-EI
5    10.10.11.58   5F-1-2     28     74:25:8a:22:ab:05  S3600V2-28TP-PWR-EI
6    10.10.11.59   5F-1-1     28     74:25:8a:29:39:b1  S3600V2-28TP-EI
7    10.10.11.61   5F-2-2     28     74:25:8a:22:b3:75  S3600V2-28TP-PWR-EI
8    10.10.11.62   5F-2-1     28     74:25:8a:29:80:91  S3600V2-28TP-EI
9    10.10.11.67   6F-1-2     28     74:25:8a:22:be:25  S3600V2-28TP-PWR-EI
10   10.10.11.68   6F-1-1     28     74:25:8a:29:1a:31  S3600V2-28TP-EI
11   10.10.11.70   6F-2-2     28     74:25:8a:22:aa:75  S3600V2-28TP-PWR-EI
12   10.10.11.71   6F-2-1     28     74:25:8a:29:7d:79  S3600V2-28TP-EI
13   10.10.11.76   7F-1-2     28     74:25:8a:22:a2:05  S3600V2-28TP-PWR-EI
14   10.10.11.77   7F-1-1     28     74:25:8a:29:36:99  S3600V2-28TP-EI
15   10.10.11.79   7F-2-2     28     74:25:8a:22:a1:bd  S3600V2-28TP-PWR-EI
16   10.10.11.80   7F-2-1     28     74:25:8a:29:1b:09  S3600V2-28TP-EI
17   10.10.11.85   8F-1-2     28     74:25:8a:22:a3:fd  S3600V2-28TP-PWR-EI
18   10.10.11.86   8F-1-1     28     74:25:8a:29:73:11  S3600V2-28TP-EI
19   10.10.11.88   8F-2-2     28     74:25:8a:22:a8:35  S3600V2-28TP-PWR-EI
20   10.10.11.89   8F-2-1     28     74:25:8a:29:7c:a1  S3600V2-28TP-EI
21   10.10.11.94   9F-1-2     28     74:25:8a:22:a8:7d  S3600V2-28TP-PWR-EI
22   10.10.11.95   9F-1-1     28     74:25:8a:29:29:19  S3600V2-28TP-EI
23   10.10.11.97   9F-2-2     28     74:25:8a:22:aa:bd  S3600V2-28TP-PWR-EI
24   10.10.11.98   9F-2-1     28     74:25:8a:9e:d3:26  S3600V2-28TP-EI
25   10.10.11.100  10F-1-2    28     74:25:8a:22:a9:9d  S3600V2-28TP-PWR-EI
26   10.10.11.101  10F-1-1    28     74:25:8a:29:38:91  S3600V2-28TP-EI
27   10.10.11.103  10F-2-2    28     74:25:8a:22:a5:65  S3600V2-28TP-PWR-EI
28   10.10.11.104  10F-2-1    28     74:25:8a:29:65:d9  S3600V2-28TP-EI
29   10.10.11.106  11F-1-1    28     74:25:8a:9f:0b:f6  S3600V2-28TP-EI
30   10.10.11.107  11F-2-2    28     74:25:8a:22:b0:a5  S3600V2-28TP-PWR-EI
31   10.10.11.108  11F-2-1    28     74:25:8a:9f:1b:fe  S3600V2-28TP-EI
32   10.10.11.109  12F-1-3    28     74:25:8a:22:a4:45  S3600V2-28TP-PWR-EI
33   10.10.11.110  12F-1-2    28     74:25:8a:29:78:b1  S3600V2-28TP-EI
34   10.10.11.112  12F-2-1    28     74:25:8a:29:7c:e9  S3600V2-28TP-EI
35   10.10.11.113  12F-1-1    26     74:25:8a:a3:20:e2  S3100V2-26TP-EI
36   10.10.11.252  H3CS7506E  98     74:25:8a:14:cd:79  S7506E
-rw-r--r-- 1 root root  444 Jan 25 19:15 /root/.shell/ip
-rw-r--r-- 1 root root  63K Jan 25 19:16 /root/snmp_info_list.txt
-rw-r--r-- 1 root root 2.8K Jan 25 19:16 ./snmp_sort.info
[[email protected] ~]# ./snmp_info.sh cisco
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
No.  IP            Hostname                        Ports  MAC               Platform
1    172.31.14.10  SW01967-HSIA-4503-01            69     0:1d:45:54:bf:7f  (cat4500-IPBASEK9-M)
2    172.31.14.11  SW01967-HSIA-SF2-2960-01        50     0:1f:c9:d8:b:41   (C2960-LANBASE-M)
3    172.31.14.12  SW01967-HSIA-SF2-2960-02        26     0:1e:f6:c7:2b:c1  (C2960-LANBASE-M)
4    172.31.14.13  SW01967-WLAN-SF2-3560-01        26     0:1f:c9:f:67:41   (C3560-IPBASE-M)
5    172.31.14.14  SW01967-WLAN-NF2-3560-01        26     0:1f:6d:da:f4:c1  (C3560-IPBASE-M)
6    172.31.14.15  SW01967-PHONE-NF4-3560-01       26     0:21:1b:0:11:c1   (C3560-IPBASE-M)
7    172.31.14.16  SW01967-WLAN-NF4-3560-01        26     0:1f:c9:f:62:c1   (C3560-IPBASE-M)
8    172.31.14.17  SW01967-HSIA-F7-2960-01.pnp.gw  50     0:1f:c9:d7:ee:41  (C2960-LANBASE-M)
9    172.31.14.18  SW01967-PHONE-F7-3560-01        26     0:1f:c9:9f:eb:41  (C3560-IPBASE-M)
10   172.31.14.19  SW01967-HSIA-F8-2960-01         50     0:1f:c9:d7:f0:41  (C2960-LANBASE-M)
11   172.31.14.20  SW01967-PHONE-F8-3560-01        26     0:21:1b:0:10:c1   (C3560-IPBASE-M)
12   172.31.14.21  SW01967-PHONE-F8-3560-02        26     0:21:1b:0:14:c1   (C3560-IPBASE-M)
13   172.31.14.22  SW01967-WLAN-F8-3560-01         26     0:1f:c9:f:77:41   (C3560-IPBASE-M)
14   172.31.14.23  SW01967-HSIA-F10-2960-01        50     0:1f:c9:d7:bb:c1  (C2960-LANBASE-M)
15   172.31.14.24  SW01967-PHONE-F10-3560-01       26     0:1f:c9:f:63:41   (C3560-IPBASE-M)
16   172.31.14.25  SW01967-PHONE-F10-3560-02       26     0:1f:6d:39:99:c1  (C3560-IPBASE-M)
17   172.31.14.26  SW01967-HSIA-F12-2960-01        50     0:1f:c9:d5:34:c1  (C2960-LANBASE-M)
18   172.31.14.27  SW01967-PHONE-F12-3560-01       26     0:21:1b:0:4:c1    (C3560-IPBASE-M)
19   172.31.14.28  SW01967-PHONE-F12-3560-02       26     0:21:1b:0:f:c1    (C3560-IPBASE-M)
20   172.31.14.29  SW01967-WLAN-F12-3560-01        26     0:1f:c9:9f:f8:c1  (C3560-IPBASE-M)
21   172.31.14.30  SW01967-HSIA-F14-2960-01        50     0:1f:c9:d8:23:c1  (C2960-LANBASE-M)
22   172.31.14.31  SW01967-PHONE-F14-3560-01       26     0:1f:9e:e2:a5:c1  (C3560-IPBASE-M)
23   172.31.14.32  SW01967-PHONE-F14-3560-02       26     0:1f:9e:e2:a1:41  (C3560-IPBASE-M)
24   172.31.14.33  SW01967-HSIA-F16-2960-01        50     0:1f:c9:a7:16:41  (C2960-LANBASE-M)
25   172.31.14.34  SW01967-PHONE-F16-3560-01       26     0:1f:c9:f:85:c1   (C3560-IPBASE-M)
26   172.31.14.35  SW01967-PHONE-F16-3560-02       26     0:21:1b:0:fc:c1   (C3560-IPBASE-M)
27   172.31.14.36  SW01967-WLAN-F16-3560-01        26     0:1f:c9:f:8d:41   (C3560-IPBASE-M)
28   172.31.14.37  SW01967-HSIA-F18-2960-01        50     0:1f:c9:d7:f3:41  (C2960-LANBASE-M)
29   172.31.14.38  SW01967-PHONE-F18-3560-01       26     0:1f:c9:9f:87:c1  (C3560-IPBASE-M)
30   172.31.14.39  SW01967-PHONE-F18-3560-02       26     0:1f:c9:9f:ff:41  (C3560-IPBASE-M)
31   172.31.14.40  SW01967-HSIA-F21-2960-01        26     0:1f:c9:d8:f3:41  (C2960-LANBASE-M)
32   172.31.14.41  SW01967-HSIA-F21-2960-02        50     0:1f:9d:fb:c2:41  (C2960-LANBASE-M)
33   172.31.14.42  SW01967-PHONE-F21-3560-01       26     0:1f:c9:f:8c:c1   (C3560-IPBASE-M)
34   172.31.14.43  SW01967-PHONE-F21-3560-02       26     0:21:1b:0:ea:c1   (C3560-IPBASE-M)
35   172.31.14.44  SW01967-HSIA-F23-2960-01        26     0:1f:c9:20:d3:c1  (C2960-LANBASE-M)
36   172.31.14.45  SW01967-HSIA-F23-2960-02        50     0:1f:c9:7b:78:41  (C2960-LANBASE-M)
37   172.31.14.46  SW01967-PHONE-F23-3560-01       26     0:1f:c9:f:92:c1   (C3560-IPBASE-M)
38   172.31.14.47  SW01967-PHONE-F23-3560-02       26     0:1f:9d:9f:3d:c1  (C3560-IPBASE-M)
39   172.31.14.48  SW01967-WLAN-F23-3560-01        26     0:1f:9d:9f:3c:c1  (C3560-IPBASE-M)
40   172.31.14.49  SW01967-HSIA-F25-2960-01        26     0:21:1b:39:f7:c1  (C2960-LANBASE-M)
41   172.31.14.50  SW01967-HSIA-F25-2960-02        50     0:1e:79:c9:99:c1  (C2960-LANBASE-M)
42   172.31.14.51  SW01967-PHONE-F25-3560-01       26     0:1f:6d:39:c0:41  (C3560-IPBASE-M)
43   172.31.14.52  SW01967-PHONE-F25-3560-02       26     0:1f:c9:f:72:41   (C3560-IPBASE-M)
44   172.31.14.53  SW01967-HSIA-F27-2960-01        26     0:21:1b:39:e7:c1  (C2960-LANBASE-M)
45   172.31.14.54  SW01967-HSIA-F27-2960-02        50     0:1f:9d:fb:de:41  (C2960-LANBASE-M)
46   172.31.14.55  SW01967-PHONE-F27-3560-01       26     0:1f:c9:f:86:c1   (C3560-IPBASE-M)
47   172.31.14.56  SW01967-PHONE-F27-3560-02       26     0:21:1b:0:f8:41   (C3560-IPBASE-M)
48   172.31.14.57  SW01967-WLAN-F27-3560-01        26     0:1f:c9:f:73:41   (C3560-IPBASE-M)
49   172.31.14.58  SW01967-HSIA-F29-2960-01        26     0:21:1b:39:f0:c1  (C2960-LANBASE-M)
50   172.31.14.59  SW01967-HSIA-F29-2960-02        50     0:1f:9d:fb:c1:41  (C2960-LANBASE-M)
51   172.31.14.60  SW01967-PHONE-F29-3560-01       26     0:1f:9e:e3:14:41  (C3560-IPBASE-M)
52   172.31.14.61  SW01967-PHONE-F29-3560-02       26     0:1f:6d:db:a7:41  (C3560-IPBASE-M)
53   172.31.14.62  SW01967-HSIA-F31-2960-01        26     0:1f:c9:a7:b0:c1  (C2960-LANBASE-M)
54   172.31.14.63  SW01967-HSIA-F31-2960-02        50     0:1f:c9:7b:e8:c1  (C2960-LANBASE-M)
55   172.31.14.64  SW01967-PHONE-F31-3560-01       26     0:1f:9e:e2:a2:c1  (C3560-IPBASE-M)
56   172.31.14.65  SW01967-PHONE-F31-3560-02       26     0:21:1b:0:0:c1    (C3560-IPBASE-M)
57   172.31.14.66  SW01967-WLAN-F31-3560-01        26     0:1f:c9:f:70:c1   (C3560-IPBASE-M)
58   172.31.14.67  SW01967-HSIA-F33-2960-01        50     0:1f:c9:d8:0:c1   (C2960-LANBASE-M)
59   172.31.14.69  SW01967-PHONE-F33-3560-01       26     0:1f:c9:9f:fd:41  (C3560-IPBASE-M)
60   172.31.14.70  SW01967-PHONE-F33-3560-02       26     0:21:1b:0:f:41    (C3560-IPBASE-M)
-rw-r--r-- 1 root root 1.9K Jan 25 19:18 /root/.shell/ip
-rw-r--r-- 1 root root 142K Jan 25 19:24 /root/snmp_info_list.txt
-rw-r--r-- 1 root root 5.7K Jan 25 19:24 ./snmp_sort.info

排错:
Timeout: No Response from 192.168.201.90
Timeout: No Response from 192.168.201.90
Timeout: No Response from 192.168.201.90
Timeout: No Response from 192.168.201.90
Timeout: No Response from 192.168.201.90
Timeout: No Response from 192.168.201.90

运行脚本./snmp_info.sh出现如上错误时,检查此交换机是否配置了snmp并且是否配置正确!

转载请注明:林志斌 » 通过SNMP收集交换机信息

发表评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址