[SNMP4J] No response from remote agent on GET

Chris cpj1 at visi.com
Tue Apr 3 20:29:00 CEST 2007


I'm trying to perform a simple SNMP get operation against a OID.
According to a packet trace, the following code sends out a packet, but
there is no received from the agent.  Manual attempts to grab the same
data from the snmpget command do return a valid result.

Any ideas what I'm doing wrong?

import org.snmp4j.*;
import org.snmp4j.smi.*;
import org.snmp4j.transport.*;
import org.snmp4j.mp.*;
import org.snmp4j.event.*;


public class SnmpTest1 {
        public static void main(String[] args) {
        Address targetAddress =
GenericAddress.parse("udp:10.0.0.209/161");
        TransportMapping transport = null;
        try {
                transport = new DefaultUdpTransportMapping();
                transport.listen();
        } catch (Exception e) {
                System.err.println("Transport Failure");
        }
        Snmp snmp = new Snmp(transport);
        CommunityTarget target = new CommunityTarget();
        target.setCommunity(new OctetString("public"));
        target.setAddress(targetAddress);
        target.setRetries(1);
        target.setTimeout(5000);
        target.setVersion(SnmpConstants.version2c);
        PDU pdu = new PDU();
        pdu.setType(org.snmp4j.PDU.GET);
        pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0")));
        ResponseEvent response = null;
        try {
                response = snmp.send(pdu,target);
        } catch (Exception e) {
                System.err.println("Send failure!");
        }
        PDU respPdu = response.getResponse();
        if (respPdu == null) {
                System.out.println("No object returned");
        }
        }
}



--------------------
Christopher Josephes
cpj1 at visi.com



More information about the SNMP4J mailing list