Java 实例 - 获取本机ip地址及主机名
Java 教程
· 2019-02-11 20:27:52
以下实例演示了如何使用 InetAddress 类的 getLocalAddress() 方法获取本机ip地址及主机名:
Main.java 文件
import java.net.InetAddress;
public class Main {
public static void main(String[] args)
throws Exception {
InetAddress addr = InetAddress.getLocalHost();
System.out.println("Local HostAddress:
"+addr.getHostAddress());
String hostname = addr.getHostName();
System.out.println("Local host name: "+hostname);
}
}
以上代码运行输出结果为:
Local HostAddress: 192.168.1.4 Local host name: harsh
点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html
The Web Designer's Idea Book
Patrick Mcneil / How / 2008-10-6 / USD 25.00
The Web Designer's Idea Book includes more than 700 websites arranged thematically, so you can find inspiration for layout, color, style and more. Author Patrick McNeil has cataloged more than 5,000 s......一起来看看 《The Web Designer's Idea Book》 这本书的介绍吧!