import java.net.InetAddress;
import java.net.UnknownHostException;
public class GetIP {
public static void main(String[] args) {
InetAddress address = null;
try {
address = InetAddress.getByName("www.baidu.com");
} catch (UnknownHostException e) {
e.printStackTrace();
}
System.out.println(address.getHostName()+":"+address.getHostAddress());
System.exit(0);
}
}
![img_e26da4baa9e11754edac6f4e817b0474.png](https://yqfile.alicdn.com/img_e26da4baa9e11754edac6f4e817b0474.png?x-oss-process=image/resize,w_1400/format,webp)