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);
}
}
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcuQzN0AjY3EDOlRjZ2MWYkVGN1cTMxUWOhFmY0EGZ2ITZfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.png)