通过 InetAddress.getByName("192.18.97.39").getHostName()
其中 192.18.97.39 是 IP 地址。 参考以下示例。
import java.io.*;
import java.net.*;
public class InetDemo {
public static void main(String[] args) {
try {
InetAddress ip = InetAddress.getByName("195.201.10.8");
System.out.println("Host Name: " + ip.getHostName());
} catch (Exception e) {
System.out.println(e);
}
}
}