public static InetAddress InetAddressByIPv6 ( String address ) { StringTokenizer addressTokens = new StringTokenizer ( address , ":" ) ; byte [ ] bytes = new byte [ 16 ] ; if ( addressTokens . countTokens ( ) == 8 ) { int count = 0 ; while ( addressTokens . hasMoreTokens ( ) ) { int word = Integer . parseInt ( addressTokens . nextToken ( ) , 16 ) ; bytes [ count * 2 ] = ( byte ) ( ( word >> 8 ) & 0xff ) ; bytes [ count * 2 + 1 ] = ( byte ) ( word & 0xff ) ; count ++ ; } } else { return null ; } try { return InetAddress . getByAddress ( bytes ) ; } catch ( UnknownHostException e ) { return null ; } }
Convert defined string to IPv6 object instance