[SNMP4J] No response from remote agent on GET
Chris
cpj1 at visi.com
Tue Apr 3 22:27:52 CEST 2007
Figured it out.
Even though I did use the listen() method to my TransportMethod instance,
it didn't seem to work until after I created my Snmp instance. So, I
moved the method call and I received the datagram back from the agent.
Snmp snmp = new Snmp(transport);
try {
transport.listen();
} catch .....
}
On Tue, 3 Apr 2007, Chris wrote:
> 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
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j
>
--------------------
Christopher Josephes
cpj1 at visi.com
More information about the SNMP4J
mailing list