我在经理方面收到“版本不正确或解码错误”。我曾是 只是想知道下面的示例陷阱发送者代码是否缺少某些内容。
public class SampleTrapSender {
public static void main(String[] args) {
String address = "172.27.41.101";
String port = "162";
address = address + "/" + port;
System.out.println("Target adddress ...." + address);
try{
Snmp snmp = new Snmp(new
DefaultUdpTransportMapping());
PDU trap = new PDU();
trap.setType(PDU.TRAP);
OID oid = new OID("1.3.6.1.4.1.4976.2.1.1.0");
Variable var = new OctetString("Test Message");
trap.add(new VariableBinding(oid, var));
Address targetAddress = new UdpAddress(address);
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString(""));
target.setVersion(SnmpConstants.version2c);
target.setAddress(targetAddress);
snmp.send(trap, target, null, null);
System.out.println("DONE......");
}catch(IOException exception){
exception.printStackTrace();
}
}
}
答案 0 :(得分:0)
试试,
PDUv1 pdu = new PDUv1();
我认为你的代码是对的。但您可以尝试使用我的代码:
try {
Address targetAddress = GenericAddress.parse("udp:"+serverIp+"/162");
TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();
Snmp snmp = new Snmp(transport);
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setVersion(SnmpConstants.version2c);
PDUv1 pdu = new PDUv1();
pdu.setType(PDU.TRAP);
OID trap = new OID("1.3.6.1.6.3.1.1.4.1.0");
VariableBinding vb = new VariableBinding();
vb.setOid(trap);
vb.setVariable(new OctetString("1.3.6.1.4.1.9.9.46.2.0.11"));//11,10
pdu.add(vb);
VariableBinding vb2 = new VariableBinding();
vb2.setOid(new OID("1.3.6.1.4.1.9.9.46.1.3.1.1.4.1.80"));
vb2.setVariable(new OctetString("VLAN0080"));
pdu.add(vb2);
snmp.send(pdu, target);
} catch (IOException e) {
e.printStackTrace();
}
我希望它会有所帮助。