网络编程中获取域名和id的方法
package com.lanqiao.java.test;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class testInetAddress {
public static void main(String[] args) throws Exception {
InetAddress inet=InetAddress.getByName("www.atguigu.com");//通过域名获取
System.out.println(inet);//获取域名和ip
System.out.println(inet.getHostName());//获取ip地址对应的域名
System.out.println(inet.getHostAddress());//获取ip地址
System.out.println();
InetAddress inet1=InetAddress.getLocalHost();//获取本机的ip,域名
System.out.println(inet1);
System.out.println(inet1.getHostName());//获取本机域名
System.out.println(inet1.getHostAddress());//获取本机的ip地址
}
}