rendered paste body#!/usr/bin/env python# -*- coding: utf-8 -*-from twisted.internet import reactor, deferfrom pysnmp.entity import engine, configfrom pysnmp.carrier.twisted import dispatchfrom pysnmp.carrier.twisted.dgram import udpfrom pysnmp.entity.rfc3413.twisted import cmdgendef receiveResponse((errorIndication, errorStatus, errorIndex, varBinds)): if errorIndication or errorStatus: print 'Error: ', errorIndication, errorStatus.prettyPrint(), errorIndex return for oid, val in varBinds: if val is None: print oid.prettyPrint() else: print '%s = %s' % (oid.prettyPrint(), val.prettyPrint())snmpEngine = engine.SnmpEngine()snmpEngine.registerTransportDispatcher(dispatch.TwistedDispatcher())config.addSocketTransport(snmpEngine, udp.domainName, udp.UdpTwistedTransport().openClientMode())host = { 'host1' : { 'community' : 'public', 'host' : '10.24.0.1' }, 'host2' : { 'community' : 'public', 'host' : '10.24.0.9' }, }getCmdGen = cmdgen.GetCommandGenerator()for h in host: print host[h] user = '%s-%s' % (h, 'user') param = '%s-%s' % (h, 'param') target = '%s-%s' % (h, 'target') config.addV1System(snmpEngine, user, host[h]['community'], transportTag=h) config.addTargetParams(snmpEngine, param, user, 'noAuthNoPriv', 1) config.addTargetAddr( snmpEngine, target, config.snmpUDPDomain, (host[h]['host'], 161), param, tagList=h) df = getCmdGen.sendReq( snmpEngine, target, (((1,3,6,1,2,1,1,1,0), None),) ) df.addCallback(receiveResponse)reactor.run()