Get Ipv6 Full Format In Java

时间:2016-02-03 04:27:43

标签: java ipv6

I have an ipv6 like:"2001:cdba::3257:9652". I want get ipv6 in full format like: 2001:cdba:0000:0000:0000:0000:3257:9652. Does has any function in java to do that? And how to compress a ipv6 full format? Thanks all.

1 个答案:

答案 0 :(得分:2)

标准Java库中没有方法可以做到这一点。

The IPAddress Java library有生成这些格式和各种其他字符串格式的方法。

以下是代码示例:

    IPAddressString addrString = new IPAddressString("2001:cdba::3257:9652");
    IPAddress addr = addrString.getAddress();
    String string = addr.toFullString();
    System.out.println(string);
    string = addr.toCanonicalString();
    System.out.println(string);

输出结果为:

2001:cdba:0000:0000:0000:0000:3257:9652
2001:cdba::3257:9652