Here is the code I wrote for the hard code a foo system name. DNS resolution in Java for passing test cases. Its advantage is to add your specific settings for standard DNS resolution during Java execution.
I recommend not to run it during production . The reflection classes and the Java runtime are used without user intervention.
private static final String FOO_IP = "10.10.8.111"; @SuppressWarnings("restriction") public static class MyHostNameService implements sun.net.spi.nameservice.NameService { @Override public InetAddress[] lookupAllHostAddr(String paramString) throws UnknownHostException { if ("foo".equals(paramString) || "foo.domain.tld".equals(paramString)) { final byte[] arrayOfByte = sun.net.util.IPAddressUtil.textToNumericFormatV4(FOO_IP); final InetAddress address = InetAddress.getByAddress(paramString, arrayOfByte); return new InetAddress[] { address }; } else { throw new UnknownHostException(); } } @Override public String getHostByAddr(byte[] paramArrayOfByte) throws UnknownHostException { throw new UnknownHostException(); } } static {
Hope this helps, but again, to be careful!
Yves martin
source share