zenis zenis - 2 years ago 77
Java Question

How could I encode ip address using bouncy castle library?

I am trying to realize snmpset using java,
and I am using bouncy castle version 1.52 library to encode the values of oids, and now I want to encode an IP address, how could I reallize it?
I tried this:

new GeneralName(GeneralName.iPAddress,"xx.xx.xx.xx");


but get a


snmpInASNParseErrs


error

UPDATE:

OK, I think i am very near to the right answer now, I used this:

InetAddress ip = InetAddress.getByName("xx.xx.xx.xx");
byte[] bytes = ip.getAddress();
v.add(new DERApplicationSpecific(0, new DEROctetString(bytes)));


now, the result is:


C/x/IpAddress_04_04_0a_00_00_64


still need more help!

Answer Source

Finally, I solved this problem by this:

InetAddress ip = InetAddress.getByName(ipv4Address);
byte[] bytes = ip.getAddress();
v.add(new DERApplicationSpecific(0, bytes));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download