package cn.dss.studay网络编程; import java.net.InetAddress; import java.net.UnknownHostException; public class InetAddressDemo { public static void main(String[] args) throws UnknownHostException { // 本地 InetAddress localHost = InetAddress.getLocalHost(); byte[] address = localHost.getAddress(); // InetAddress localHostname = InetAddress.getByName(""); // 本地回环地址。 InetAddress loopbackAddress = InetAddress.getLoopbackAddress(); System.out.println(localHost); System.out.println(loopbackAddress); InetAddress byName = InetAddress.getByName("PC-dss2019"); System.out.println(byName); String hostAddress = byName.getHostAddress(); System.out.println(hostAddress); InetAddress[] allByName = InetAddress.getAllByName("www.baidu.com"); for( InetAddress name:allByName){ // System.out.println(allByName.toString()); System.out.println(name); } } }
java中InetAddress
最新推荐文章于 2022-10-14 09:24:32 发布