def __init__(self, ctx, database): StreamBase.__init__(self, ctx, database) if SNMPBase.PROXY is None: port = snmpprotocol.port() SNMPBase.PROXY = agentproxy.AgentProxy( "127.0.0.1", 161, community="public", snmpVersion="v2", protocol=port.protocol ) self.proxy = SNMPBase.PROXY
def __init__(self, process, proto): self.proto = proto self.peer = self.proto.transport.getPeer() self.host = self.peer.host self.process = process self.i = 0 self.last_aspath = '' self.ifs = {} self.rt = radix.Radix() log.msg("init of peer: ", self.host) self.reinit() self.snmp_protocol = snmpprotocol.port()
logging.basicConfig() # need to get the ip address usage = """Usage: simpleget ipAddress port community baseoid... ipAddress -- dotted IP address of the agent port -- numeric port number of the agent community -- community string for the agent baseoid -- dotted set of OIDs to retrieve from agent """ if len(sys.argv) < 4: print usage sys.exit(1) ipAddress = sys.argv[1] # choose random port in range 25000 to 30000 port = snmpprotocol.port() targetPort = int(sys.argv[2]) proxy = agentproxy.AgentProxy( ipAddress, targetPort, community=sys.argv[3], snmpVersion='v2', protocol=port.protocol, ) if not sys.argv[4:]: oids = [ '.1.3.6.1.2.1.1.1.0', 'New Description', '.1.3.6.1.2.1.1.4.0', '*****@*****.**', ]
def createClientPort( self ): """Get our client port (and the attached protocol)""" return snmpprotocol.port( )
('.1.3.6.1.2.1.1.1.0', 'Hello world!'), ('.1.3.6.1.2.1.1.2.0', 32), ('.1.3.6.1.2.1.1.3.0', v1.IpAddress('127.0.0.1')), ('.1.3.6.1.2.1.1.4.0', v1.OctetString('From Octet String')), ('.1.3.6.1.2.1.2.1.0', 'Hello world!'), ('.1.3.6.1.2.1.2.2.0', 32), ('.1.3.6.1.2.1.2.3.0', v1.IpAddress('127.0.0.1')), ('.1.3.6.1.2.1.2.4.0', v1.OctetString('From Octet String')), ('.1.3.6.2.1.0', 'Hello world!'), ('.1.3.6.2.2.0', 32), ('.1.3.6.2.3.0', v1.IpAddress('127.0.0.1')), ('.1.3.6.2.4.0', v1.OctetString('From Octet String')), ] ), ), ), ) print 'Starting listening agent' reactor.run() else: from twistedsnmp import agentproxy, snmpprotocol port = snmpprotocol.port() proxy = agentproxy.AgentProxy( ip = '127.0.0.1', community = 'public', protocol = port.protocol, port = 20161, ) proxy.verbose = 1 print synchronous( 0, proxy.getTable, ('.1.3.6.1.2.1.1',) )