package com.leo;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class InetAddressTest {
public static void main(String[] args) throws UnknownHostException {
InetAddress inet1 = InetAddress.getByName("127.0.0.1");
System.out.println(inet1);
InetAddress inet2 = InetAddress.getByName("www.baidu.com");
System.out.println(inet2);
// 获取本地ip
InetAddress localHost = InetAddress.getLocalHost();
System.out.println(localHost);
// getHostName()
String hostName = inet2.getHostName();
System.out.println(hostName);
// getHostAddress()
String hostAddress = inet2.getHostAddress();
System.out.println(hostAddress);
}
}