有没有办法在 java 中测试 SNMP 连接的可用性?我正在使用推理api。
try {
long timeTicks = System.currentTimeMillis();
while (timeTicks > 4294967295L) { timeTicks-= 4294967295L; }
SnmpTrap trap = new SnmpTrap(timeTicks, new SnmpOID(oid));
try {
InetAddress inet = InetAddress.getByName(agentIp);
agentIp = inet.getHostAddress();
} catch (Exception e2) {
System.out.println("SendSNMPTrap::sendVersion2c unable to resolve "+agentIp+" to real IP. Exception="+e2.toString());
}
trap.addVarBinds(vb.getVarbinds());
SnmpTrapSender.sendTrap(destHost, port, trap, true, community);
} catch (Exception e) {
logger.error("SendSNMPTrap::sendVersion2c Exception="+e.toString());
result = false;
}