我正在尝试使用java实现snmpset, 我正在使用 bouncy caSTLe 版本 1.52 库对 oid 的值进行编码,现在我想对 IP 地址进行编码,我该如何实现呢? 我试过这个:
new GeneralName(GeneralName.iPAddress,"xx.xx.xx.xx");
但是得到一个
snmpInASNParseErrs
错误
更新:
好的,我想我现在已经非常接近正确的答案了,我使用了这个:
InetAddress ip = InetAddress.getByName("xx.xx.xx.xx");
byte[] bytes = ip.getAddress();
v.add(new DERApplicationSpecific(0, new DEROctetString(bytes)));
现在,结果是:
C/x/IpAddress_04_04_0a_00_00_64
仍然需要更多帮助!
最佳答案
最后,我通过以下方式解决了这个问题:
InetAddress ip = InetAddress.getByName(ipv4Address);
byte[] bytes = ip.getAddress();
v.add(new DERApplicationSpecific(0, bytes));
关于java - 如何使用 bouncy caSTLe 库对 IP 地址进行编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45298896/