|
I want to use snmp4j to communicate with the device. Is it necessary to know the version of snmp, and how to get oid and oid?
String ip = "192.168.100.1";
Address targetAddress = GenericAddress.parse ("udp:" + ip + "/ 161");
log.debug ("ip" + ip);
TransportMapping transport;
transport = new DefaultUdpTransportMapping ();
Snmp snmp = new Snmp (transport);
transport.listen ();
CommunityTarget target = new CommunityTarget ();
target.setCommunity (new OctetString ("public"));
target.setAddress (targetAddress);
target.setRetries (2);
target.setTimeout (1000);
target.setVersion (SnmpConstants.version1);
// creating PDU
PDU pdu = new PDU ();
String oidPrefix = "1.3.6.1.2.1.1.1";
pdu.add (new VariableBinding (new OID (oidPrefix)));
pdu.setType (PDU.GET);
ResponseEvent event = snmp.send (pdu, target);
PDU resposePDU = event.getResponse ();
Vector result = resposePDU.getVariableBindings ();
VariableBinding vb = (VariableBinding) result.get (0);
String sID = vb.getVariable (). ToString ();
log.debug ("sID" + sID);
This is not correct.Why is the value in result every time empty? I have given an example. Thank you. |
|