获取本机ip地址及主机名

获取本机ip地址及主机名


 package guyu.day0824;

 import java.net.InetAddress;

 /**
* @Author: Fred
* @Date: 2020/8/24 09:39
*/
public class Demo01 {
public static void main(String[] args) throws Exception { //使用 InetAddress 类的 getLocalAddress() 方法获取本机ip地址及主机名
InetAddress addr = InetAddress.getLocalHost();
System.out.println("Local HostAddress: "+addr.getHostAddress());
String hostname = addr.getHostName();
System.out.println("Local host name: "+hostname);
}
}

Java 实例 - 获取本机ip地址及主机名-LMLPHP
                  故屿γ                   

05-10 21:30