可以使用getLocalHost
命令:
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());
System.out.println("Local host name:" + addr.getHostName());
}
}
即可输出本机的IP和name。
学习更多编程知识,请关注我的公众号:
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。