[SNMP4J] sample agent code

Imri Zvik imriz at inter.net.il
Wed Mar 18 15:05:37 CET 2009


Hi,

The following code example will query an SNMP enabled device and dump the
response to STDOUT:

            Address targetAddress =
GenericAddress.parse("udp:111.111.111.111/161");
            CommunityTarget target = new CommunityTarget();
            target.setCommunity(new OctetString("community"));
            target.setAddress(targetAddress);
            target.setVersion(SnmpConstants.version2c);
            PDU pdu = new PDU();
            pdu.add(new VariableBinding(new OID(1.2.3.4.5.6));
            pdu.setType(PDU.GET);
            DefaultUdpTransportMapping udpTransport = new
DefaultUdpTransportMapping();
            udpTransport.setSocketTimeout(1000);
            System.out.println("Setting up socket");
            udpTransport.listen();
            Snmp snmp = new Snmp(udpTransport);
            System.out.println("Sending SNMP packet");
            ResponseEvent response = snmp.send(pdu, target);
            udpTransport.close();
            if (response.getResponse() == null) {
            // request timed out
                System.out.println("TIMEOUT waiting for a  response from: "
+ response.getPeerAddress());
            } else {
                System.out.println("Received response from: " +
response.getPeerAddress());
                // dump response PDU
                System.out.println(response.getResponse().toString());
		}

-----Original Message-----
From: VijayMajagaonkar [mailto:vijaymajagaonkar at gmail.com] 
Sent: Wednesday, March 18, 2009 3:57 PM
To: snmp4j at agentpp.org
Subject: [SNMP4J] sample agent code

hello people,

  can any one send me the sample code for agent using these API, i m
new to the agent side coding as, i worked with the
SNMP manager i m bit confused how to make use of  agent api in the
client side machine,
any body help or show me the first step......


-- 
"Human Knowledge Belongs To World"
Thanks
Vm
_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j




More information about the SNMP4J mailing list