Permalink
Browse files

Add InetAddressUtil.convertToInetAddressIfPossible(CharSequence address)

  • Loading branch information...
Flowdalic committed Dec 7, 2018
1 parent 0d53969 commit 61fd2e8d0179521025d13162745093c75372b088
Showing with 14 additions and 0 deletions.
  1. +14 −0 minidns-core/src/main/java/org/minidns/util/InetAddressUtil.java
@@ -73,6 +73,20 @@ public static boolean isIpAddress(CharSequence address) {
return isIpV6Address(address) || isIpV4Address(address);
}

public static InetAddress convertToInetAddressIfPossible(CharSequence address) {
if (!isIpAddress(address)) {
return null;
}

String addressString = address.toString();
try {
return InetAddress.getByName(addressString);
} catch (UnknownHostException e) {
// Should never happen.
throw new AssertionError(e);
}
}

public static DnsName reverseIpAddressOf(Inet6Address inet6Address) {
final String ipAddress = inet6Address.getHostAddress();
final String[] ipAddressParts = ipAddress.split(":");

0 comments on commit 61fd2e8

Please sign in to comment.