snmp get from pysnmp.entity.rfc3413.oneliner import cmdgen import time SNMP_HOST_scr = ['172.30.95.206', '172.30.95.212' ] SNMP_PORT = 161 SNMP_COMMUNITY = 'public' OID_sysDescr = '1.3.6.1.2.1.1.1.0' # bash shell command: #snmpget -v2c -cpublic 172.30.95.206 1.3.6.1.2.1.1.1.0 for ip in SNMP_HOST_scr: SNMP_HOST = ip print(SNMP_HOST) cmdGen = cmdgen.CommandGenerator() errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( cmdgen.CommunityData(SNMP_COMMUNITY), cmdgen.UdpTransportTarget((SNMP_HOST, SNMP_PORT)),OID_sysDescr) # Check for errors and print out results if errorIndication: print(errorIndication) elif errorStatus: print('%s at %s' % ( errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1] or '?') ) else: for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) #print("\n",val.prettyPrint()) | |
General
Content
Integrations