import java.net.InetAddress; public class SimpleDNS { public static void main(String[] args) { getAllDNS(); getDNS(); } private static void getAllDNS() { try { InetAddress[] address = InetAddress.getAllByName("www.google.com"); for (int i = 0; i < address.length; i++) { System.out.println(address[i].getHostAddress()); } } catch (Exception e) { System.out.println(e.toString()); System.exit(1); } } private static void getDNS() { try { InetAddress address = InetAddress.getByName("mdm.zte.com.cn"); System.out.println(address.getHostAddress()); } catch (Exception e) { System.out.println(e.toString()); System.exit(1); } } }
getAllDNS获取域名解析的所有IP地址
getDNS获取域名解析地址单个