我尝试使用snmp4j实现snmpgetbulk函数,但未能获取所有记录。它总是给我100条记录。任何人都可以就此提出建议吗?
以下是我的代码:
//create transport
transport = new DefaultUdpTransportMapping();
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(3);
target.setTimeout(5000);
target.setVersion(1);
// create the PDU
PDU pdu = new PDU();
pdu.setType(PDU.GETBULK);
//put the oid you want to get
pdu.add(new VariableBinding(new OID(oid)));
pdu.setMaxRepetitions(150);
//pdu string
System.out.println("pdu " + pdu.toString());
response = snmp.getBulk(pdu,target);
System.out.println("pdu.size>>"+pdu.size());
if(response != null) {
if(response.getResponse().getErrorStatusText().equalsIgnoreCase("Success")) {
PDU pduresponse=response.getResponse();
Vector vec = pduresponse.getVariableBindings();
System.out.println("snmpwalk2>> size>>"+vec.size());
for(int i=0; i<vec.size(); i++){
VariableBinding vb = null;
vb = (VariableBinding)vec.elementAt(i);
//System.out.println(i+ " ---- "+vb.toString());
}
}
答案 0 :(得分:0)