Arayüzler / IP Adresleme:
Bir cihazın IP adresini, alt ağ maskesini ve ilgili arabirimi yoklamak istiyorsanız, IP-MIB ve IF-MIB MIB'lerinden aşağıdaki OID'leri kullanabilirsiniz :
.1.3.6.1.2.1.4.20.1.1
- IP adresi bu OID'de bulunabilir
~]$ snmptranslate .1.3.6.1.2.1.4.20.1.1
IP-MIB::ipAdEntAddr
~]$ snmpwalk -v2c -c cisco 10.30.46.1 .1.3.6.1.2.1.4.20.1.1
IP-MIB::ipAdEntAddr.10.30.46.1 = IpAddress: 10.30.46.1
IP-MIB::ipAdEntAddr.25.255.25.254 = IpAddress: 25.255.25.254
IP-MIB::ipAdEntAddr.55.44.33.22 = IpAddress: 55.44.33.22
IP-MIB::ipAdEntAddr.172.31.10.10 = IpAddress: 172.31.10.10
.1.3.6.1.2.1.4.20.1.3
- Alt ağ maskesi kamışı bu OID'de bulunabilir
~]$ snmptranslate .1.3.6.1.2.1.4.20.1.3
IP-MIB::ipAdEntNetMask
~]$ snmpwalk -v2c -c cisco 10.30.46.1 .1.3.6.1.2.1.4.20.1.3
IP-MIB::ipAdEntNetMask.10.30.46.1 = IpAddress: 255.255.255.0
IP-MIB::ipAdEntNetMask.25.255.25.254 = IpAddress: 255.255.255.0
IP-MIB::ipAdEntNetMask.55.44.33.22 = IpAddress: 255.255.255.0
IP-MIB::ipAdEntNetMask.172.31.10.10 = IpAddress: 255.255.255.0
.1.3.6.1.2.1.4.20.1.2
- Arayüz dizini ( ifTable Dizinleri ) her arayüz için benzersiz tamsayılardır.
~]$ snmptranslate .1.3.6.1.2.1.4.20.1.2
IP-MIB::ipAdEntIfIndex
~]$ snmpwalk -v2c -c cisco 10.30.46.1 .1.3.6.1.2.1.4.20.1.2
IP-MIB::ipAdEntIfIndex.10.30.46.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.25.255.25.254 = INTEGER: 5
IP-MIB::ipAdEntIfIndex.55.44.33.22 = INTEGER: 6
IP-MIB::ipAdEntIfIndex.172.31.10.10 = INTEGER: 7
.1.3.6.1.2.1.2.2.1.2
- Kolay arabirim adı bu OID'de bulunabilir ve ...2.1.2.[INDEX]
her arabirim için ifTable dizini eklenir (örn. ).
~]$ snmptranslate .1.3.6.1.2.1.2.2.1.2
IF-MIB::ifDescr
~]$ snmpwalk -v2c -c cisco 10.30.46.1 .1.3.6.1.2.1.2.2.1.2
IF-MIB::ifDescr.1 = STRING: FastEthernet0/0
IF-MIB::ifDescr.2 = STRING: FastEthernet0/1
IF-MIB::ifDescr.4 = STRING: Null0
IF-MIB::ifDescr.5 = STRING: Loopback0
IF-MIB::ifDescr.6 = STRING: Tunnel10
IF-MIB::ifDescr.7 = STRING: Dialer1
IF-MIB::ifDescr.8 = STRING: Virtual-Access1
Bu OID'leri manuel olarak yürütebilir, istediğiniz dilde bir şeyler yazabilir veya Tim Peck'in cevabında belirtilenlere benzer çok daha akıllı programlar / komut dosyaları kullanabilirsiniz.
İşte hızlı (ve kirli) bir kabuk örneği:
#!/bin/bash
# duct taped by one.time
# Basic interface information collector
##
# Set usage var and getoptions
usage="Usage: interface-info.sh -H <IP Address> -C <snmp community string>
OPTIONS:
-H Hostname set IP address or hostname
-h Help prints usage options
SNMPv2 OPTIONS:
-C Community set SNMPv2 community string
"
while getopts H:C:h option;
do
case $option in
H) ipaddress=$OPTARG;;
C) community=$OPTARG;;
h) echo "$usage"
exit $invalid_result;;
esac
done
##
# Prevent blank argvars
if [[ -z $ipaddress || -z $community ]]; then
echo "$usage"
exit 0
fi
##
# Set field separator to new line
IFS=$'\n'
##
# Store our IP-MIB info in arrays
ipAdEntAddr=( $(snmpbulkwalk -v2c -c $community $ipaddress .1.3.6.1.2.1.4.20.1.1 | awk -F ": " '{print $2}') )
ipAdEntNetMask=( $(snmpbulkwalk -v2c -c $community $ipaddress .1.3.6.1.2.1.4.20.1.3 | awk -F ": " '{print $2}') )
ipAdEntIfIndex=( $(snmpbulkwalk -v2c -c $community $ipaddress .1.3.6.1.2.1.4.20.1.2 | awk -F ": " '{print $2}') )
for ((i=0; i<${#ipAdEntAddr[@]}; i++)); do
ifDescr[$i]=$(snmpwalk -v2c -c $community $ipaddress .1.3.6.1.2.1.2.2.1.2.${ipAdEntIfIndex[$i]} | awk -F ": " '{print $2}')
echo "${ifDescr[$i]}: ${ipAdEntAddr[$i]} ${ipAdEntNetMask[$i]}"
done
Misal:
~]$ ./interface-info.sh -H 10.30.46.1 -C cisco
FastEthernet0/0: 10.30.46.1 255.255.255.0
Loopback0: 25.255.25.254 255.255.255.0
Tunnel10: 55.44.33.22 255.255.255.0
Dialer1: 172.31.10.10 255.255.255.0
VLAN:
VLAN kimliklerini ve VLAN adlarını arıyorsanız, aşağıdaki OID'yi kullanabilirsiniz:
.1.3.6.1.4.1.9.9.46.1.3.1.1.4.1
VtpVlanName Bu OSB de ve VLAN-ID, ekteki bulunabilir, örneğin, (Cisco cihazlarda) bulunabilir ...1.4.1.[VLAN-ID]
(ifIndex ve ifDescr Yukarıdaki örnekte benzer).
~]$ snmptranslate .1.3.6.1.4.1.9.9.46.1.3.1.1.4.1
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1
~]$ snmpwalk -v2c -c cisco 192.168.0.8 SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1.1 = STRING: "default"
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1.10 = STRING: "VLAN0010"
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1.21 = STRING: "VLAN0021"
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1.100 = STRING: "VLAN0100"
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1.344 = STRING: "VLAN0344"
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1.456 = STRING: "iSCSI-TRAFFIC"
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1.1002 = STRING: "fddi-default"
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1.1003 = STRING: "token-ring-default"
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1.1004 = STRING: "fddinet-default"
SNMPv2-SMI::enterprises.9.9.46.1.3.1.1.4.1.1005 = STRING: "trnet-default"
VLAN kimliklerini kazıma ile ilgili manuel örnek:
~]$ snmpbulkwalk -v2c -c cisco 192.168.0.8 1.3.6.1.4.1.9.9.46.1.3.1.1.4 | sed -e 's/.*4.1.\(.*\) =.*/\1/'
1
10
21
100
344
456
1002
1003
1004
1005