Created
May 12, 2015 02:34
-
-
Save twr14152/a1727058322b78641d81 to your computer and use it in GitHub Desktop.
Testing pysnmp out on All-in-one-VM
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 pysnmp.entity.rfc3413.oneliner import cmdgen | |
cmdGen = cmdgen.CommandGenerator() | |
# Run through these hosts | |
IP = ['10.10.10.110', '10.10.10.120', '10.10.10.130'] | |
# | |
#http://tools.cisco.com/Support/SNMP/do/BrowseOID.do?local=en&translate=Translate&objectInput=1.3.6.1.2.1.1.1#oidContent | |
# | |
def main(): | |
for ip in IP: | |
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( | |
cmdgen.CommunityData('password'), | |
cmdgen.UdpTransportTarget((ip, 161)), | |
cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0), | |
cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0), | |
lookupNames=True, lookupValues=True | |
) | |
# Check for errors and print out results | |
if errorIndication: | |
print(errorIndication) | |
elif errorStatus: | |
print(errorStatus) | |
else: | |
for name, val in varBinds: | |
print('%s = %s\n' % (name.prettyPrint(), val.prettyPrint())) | |
if __name__ == '__main__': | |
main() | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results:
cisco@onepk:~/todds_scripts/snmp$ python snmp_query_ex3.py
SNMPv2-MIB::sysName."0" = Router1
SNMPv2-MIB::sysDescr."0" = Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Experimental Version 15.4(20140730:011659) [lucylee-pi25-2 107]
Copyright (c) 1986-2014 by Cisco Systems, Inc.
Compiled Tue 29-Jul-14 18:17 by lucylee
SNMPv2-MIB::sysName."0" = Router2
SNMPv2-MIB::sysDescr."0" = Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Experimental Version 15.4(20140730:011659) [lucylee-pi25-2 107]
Copyright (c) 1986-2014 by Cisco Systems, Inc.
Compiled Tue 29-Jul-14 18:17 by lucylee
SNMPv2-MIB::sysName."0" = Router3
SNMPv2-MIB::sysDescr."0" = Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Experimental Version 15.4(20140730:011659) [lucylee-pi25-2 107]
Copyright (c) 1986-2014 by Cisco Systems, Inc.
Compiled Tue 29-Jul-14 18:17 by lucylee
cisco@onepk:~/todds_scripts/snmp$