代码如下:
package InetAddressPack;import java.net.InetAddress;
import java.net.UnknownHostException;public class InetAddressDemo {public static void main(String[] args) throws UnknownHostException {
// InetAddress address = InetAddress.getByName("LAPTOP-T6O2Q8KT");InetAddress address = InetAddress.getByName("192.168.1.123");String name = address.getHostName();String ip = address.getHostAddress();System.out.println("主机名"+name);System.out.println("IP地址"+ip);}
}