“版本不正确或解码错误”发送陷阱时

发布于 2024-10-31 06:55:20 字数 1332 浏览 2 评论 0原文

我在管理器端收到“版本不正确或解码错误”。我是 只是想知道以下示例陷阱发送器代码是否缺少某些内容。

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();
               }

         }
}

I am getting "Incorrect Version or decode error" on manager side. I was
just wondering if there is something missing with the following sample trap sender code.

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();
               }

         }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

誰認得朕 2024-11-07 06:55:20

尝试一下,

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();
}

我希望它会有所帮助。

Try with,

PDUv1 pdu = new PDUv1();

I think your code is right. But you can try using my code:

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();
}

I hope it will help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文