Reputation: 91
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.
Upvotes: 2
Views: 2248
Reputation: 323
import com.google.common.net.InetAddresses;
// Convert the short IPv6 address to a full version
InetAddress inetAddress = InetAddresses.forString(shortIPv6);
return inetAddress.getHostAddress();
Upvotes: -1
Reputation: 4605
There is no method in the standard Java libraries to do that.
The IPAddress Java library has methods to produce those formats and various other string formats.
Here is a code sample:
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);
The output is:
2001:cdba:0000:0000:0000:0000:3257:9652
2001:cdba::3257:9652
Upvotes: 3