Antarmuka / Alamat IP:
Jika Anda ingin menyurvei alamat IP perangkat, subnet mask dan antarmuka yang sesuai, Anda dapat menggunakan OID berikut dari MIB IP-MIB dan IF-MIB :
.1.3.6.1.2.1.4.20.1.1
- Alamat IP dapat ditemukan di OID ini
~]$ 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
- Tongkat subnet mask dapat ditemukan di OID ini
~]$ 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
- Indeks antarmuka ( Indeks ifTable ) adalah bilangan bulat unik untuk setiap antarmuka.
~]$ 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
- Nama antarmuka yang ramah dapat ditemukan di OID ini dan indeks ifTable ditambahkan (mis. ...2.1.2.[INDEX]
) Untuk setiap antarmuka.
~]$ 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
Anda dapat menjalankan OID ini secara manual, membuat skrip sesuatu dalam bahasa pilihan Anda, atau menggunakan program / skrip yang jauh lebih cerdas mirip dengan apa yang disebutkan dalam jawaban Tim Peck.
Berikut adalah contoh shell yang cepat (dan kotor):
#!/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
Contoh:
~]$ ./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:
Jika Anda mencari ID VLAN dan nama VLAN, Anda dapat menggunakan OID berikut:
.1.3.6.1.4.1.9.9.46.1.3.1.1.4.1
The vtpVlanName dapat ditemukan (pada perangkat Cisco) di OID ini dan VLAN-ID dapat ditemukan ditambahkan, misalnya: ...1.4.1.[VLAN-ID]
(mirip dengan contoh ifIndex dan ifDescr di atas).
~]$ 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"
Contoh manual mengikis ID VLAN:
~]$ 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