1 23 package org.archive.util; 24 25 import java.net.InetAddress ; 26 27 import org.xbill.DNS.ARecord; 28 import org.xbill.DNS.DClass; 29 import org.xbill.DNS.Record; 30 import org.xbill.DNS.TextParseException; 31 import org.xbill.DNS.Type; 32 import org.xbill.DNS.Lookup;; 33 34 40 public class DNSJavaUtil { 41 private DNSJavaUtil() { 42 super(); 43 } 44 45 54 public static InetAddress getHostAddress(String host) { 55 InetAddress hostAddress = InetAddressUtil.getIPHostAddress(host); 56 if (hostAddress != null) { 57 return hostAddress; 58 } 59 60 Record[] rrecordSet; 62 try { 63 rrecordSet = (new Lookup(host, Type.A, DClass.IN)).run(); 64 } catch (TextParseException e) { 65 rrecordSet = null; 66 } 67 if (rrecordSet != null) { 68 for (int i = 0; i < rrecordSet.length; i++) { 71 if (rrecordSet[i].getType() != Type.A) { 72 continue; 73 } 74 hostAddress = ((ARecord)rrecordSet[i]).getAddress(); 75 break; 76 } 77 } 78 return hostAddress; 79 } 80 } 81 | Popular Tags |