我想通过snmp GETBULK获取路由器的接口信息,但是我使用的时候,只返回了部分记录。
代码如下:
public static void main(String[] args) throws IOException, InterruptedException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setVersion(SnmpConstants.version2c);
target.setAddress(new UdpAddress("127.0.0.1/161"));
target.setTimeout(3000); //3s
target.setRetries(1);
PDU pdu = new PDU();
pdu.setType(PDU.GETBULK);
pdu.setMaxRepetitions(200);
pdu.setNonRepeaters(0);
pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.31.1.1.1.1")));
ResponseEvent responseEvent = snmp.send(pdu, target);
PDU response = responseEvent.getResponse();
if (response == null) {
System.out.println("TimeOut...");
}
else
{
if (response.getErrorStatus() == PDU.noError)
{
Vector<? extends VariableBinding> vbs = response.getVariableBindings();
for (VariableBinding vb : vbs) {
System.out.println(vb + " ," + vb.getVariable().getSyntaxString());
}
}
else
{
System.out.println("Error:" + response.getErrorStatusText());
}
}
}
执行后,有59条记录被返回,但如果我使用GETNEXT获取它们,大约有197条记录被返回。
有任何想法吗?
希望有人可以帮助我,在此先感谢。