Java获取本机IP
文章目录
可以使用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。
学习更多编程知识,请关注我的公众号:

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论