cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
879
Views
0
Helpful
1
Replies

Get the Cisco model number via snmp command on the router/swit script

Siren
Level 1
Level 1

Hi I want to get the model number of Cisco routers and switches and I am hoping there is a way to capture the model number from the command line and putting it into a variable for TCL or VBS scripting like the command "show snmp chassis" displays the serial number on the command line.

On my machine I can get this number 1.3.6.1.4.1.9.1.576  which translates to "cisco2811" on the Cisco online SNMP Object Navigator but is there a way to get this translation on the router?

I like snmp but if there is no way to translate it on the router then I would greatly appreciate other suggestions how to get the model number into a variable in TCL. Again "show snmp chassis" works great for effortlessly displaying the machines serial number.

Router#show snmp sysObjectID
1.3.6.1.4.1.9.1.576

 

1 Reply 1

M02@rt37
VIP
VIP

Hello @Siren 

To retrieve the Cisco router model from the command line, you can use the following SNMP OID:

snmpwalk -v2c -c <community_string> <router_ip> <OID>

Note that the SNMP OID `1.3.6.1.2.1.1.2` corresponds to `sysObjectID` in the SNMP MIB, which is an OID that uniquely identifies the type of system. In the case of Cisco routers, it typically returns an OID like `1.3.6.1.4.1.9.1.X`, where `X` represents the specific model.

Here's an example of how you can use this in a shell script or within a TCL script:

#!/bin/bash

router_ip="your_router_ip"
community_string="your_community_string"

model_oid=$(snmpwalk -v2c -c $community_string $router_ip 1.3.6.1.2.1.1.2 | awk '{print $NF}')

# Extract the model from the OID
model_number=$(snmptranslate -On -Td $model_oid | grep -oP '(?<=::= STRING: ).*')

echo "Router Model: $model_number"

This script uses `snmpwalk` to get the `sysObjectID` and then `snmptranslate` to convert the OID to its corresponding string value, which should include the model information.

 

Best regards
.ı|ı.ı|ı. If This Helps, Please Rate .ı|ı.ı|ı.