我碰壁了。我有一个通过 SNMP 与 DSLAM 通信的小型系统。 几个月来一切都运行良好,但是当我最近向系统添加新的 DSLAM 时,我无法从中得到答案。尝试了其他IP,没有问题。
大约一个小时后,突然其他 DSLAM 也不再回复我了。所以现在我有两个单位没有任何沟通,这有点糟糕。所以我当然检查了单位,没有发现问题。通过我的 MIB 浏览器,我可以访问所有单元...但不能通过我的软件。所以错误出在我的软件中的某个地方。所以我检查了 Wireshark,发现 getNext 请求正在发出,但我似乎没有得到答案。当我通过 MIB 浏览器执行此操作时,就会出现答案。但有趣的是:这两个请求是相同的。所以我一定不是在听 - 是的,它正在听。
为什么这对于某些 IP 是特定的,亲爱的上帝,为什么它们会互相污染?
让我们看一些代码:
public String GetNextValue(String OID, Dslam dslam) throws IOException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
CommunityTarget target = initializeTarget(dslam);
PDU request = new PDU();
request.setType(PDU.GETNEXT);
OID oid= new OID(OID);
request.add(new VariableBinding(oid));
PDU responsePDU=null;
ResponseEvent responseEvent;
responseEvent = snmp.send(request, target);
if (responseEvent != null){
System.out.println("resonse event not null..");
responsePDU = responseEvent.getResponse();
if ( responsePDU != null){
System.out.println("pdu not null..");
@SuppressWarnings("unchecked")
Vector <VariableBinding> tmpv = (Vector<VariableBinding>) responsePDU.getVariableBindings();
if(tmpv != null){
System.out.println("tmpv not null..");
VariableBinding vb = (VariableBinding) tmpv.get(0);
if(!vb.isException()){
return vb.getVariable().toString()
}
}
}
}
_errorHandler.criticalError("Response error in DSLAM communication");
return null;
}
和初始化器:
private CommunityTarget initializeTarget(Dslam dslam){
Address addr = new UdpAddress(dslam.getAddress() + "/" + dslam.getManagementPort() );
System.out.println("IP: " + dslam.getAddress() + " port: " + dslam.getManagementPort());
CommunityTarget target = new CommunityTarget(addr, new OctetString("public"));
target.setVersion(SnmpConstants.version2c);
target.setTimeout(3000);
target.setRetries(3);
return target;
}
如果我们在工作的 DSLAM 上运行测试:
@Test
public void Lowtest() throws IOException{
SnmpController snmpController = SnmpController.GetInstance();
DslamGrabber dslamGrabber = new DslamGrabber();
Dslam dslam = dslamGrabber.getByDslamId("test5xda5");
String result = snmpController.GetNextValue(".1.3.6.1.4.1.637.61.1.39.3.3.1.1.2", dslam);
System.out.println(result);
}
结果:
IP: 195.215.96.135 port: 161
resonse event not null..
pdu not null..
tmpv not null..
OID: 1.3.6.1.4.1.637.61.1.39.3.3.1.1.2.1
BF512_2048
我们尝试对抗 test5xda9(第二个屈服于这种可怕的类似疾病的错误)
我们在 Wireshark 中重试了 3 次,并得到以下输出:
IP: 192.215.96.139 port: 161
resonse event not null..
Response error in DSLAM communication
null
我真的希望有人能帮助我。距离我还有几个小时的路程,要么泪流满面,要么毁掉 DSLAM。
最诚挚的问候 本
最佳答案
嗯,正如一位 friend 指出的那样,192 不等于 195。
关于java - SNMP 响应为空 [SNMP4j],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36769153/