-
-
Save hanynowsky/11d4e96d74558973c7d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from snimpy.manager import Manager as M | |
from snimpy.manager import load | |
from snimpy.snmp import SNMPNoSuchInstance | |
#import pymysql | |
# Load up SNMP MIBs | |
load("IF-MIB") | |
load("./mibs/CISCO-SMI.txt") | |
load("./mibs/CISCO-TC.txt") | |
load("./mibs/CISCO-VTP-MIB.txt") | |
load("./mibs/CISCO-VLAN-MEMBERSHIP-MIB.txt") | |
load("./mibs/CISCO-STACK-MIB.txt") | |
load("./mibs/CISCO-PRODUCTS-MIB.txt") | |
# Create our SNMP connection | |
manager = M(host="10.0.0.1", community="public", version=2) | |
try: | |
for ifIndex in manager.ifDescr: | |
# Only include ethernet interfaces | |
if manager.ifType[ifIndex] == 6: | |
ifAlias = manager.ifDescr[ifIndex] | |
ifDescription = manager.ifAlias[ifIndex] | |
# Check if we have a trunk or access port | |
if manager.vlanTrunkPortDynamicState[ifIndex] == 1: | |
ifType = 'trunk' | |
# Set to native vlan to 0, since it's a trunk | |
ifNativeVlan = 0 | |
else: | |
ifType = 'access' | |
# Since this is an access port, we'll also get the native VLAN | |
ifNativeVlan = manager.vmVlan[ifIndex] | |
ifStatus = manager.ifAdminStatus[ifIndex] | |
ifLastStateChange = manager.ifLastChange[ifIndex] | |
values = (str(ifAlias), ifType, int(ifNativeVlan), int(ifIndex), 1, str(ifDescription), int(ifStatus)) | |
print(values) | |
except SNMPNoSuchInstance: | |
pass | |
finally: | |
print('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment