|
我想使用snmp4j与设备通信,是不是首先要知道snmp的版本,和oid,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);
这样取对不对,为什么每次result 中的值都是空的,有做过的兄弟给个例子吧,多谢了 |
|