提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用InetAddress获取IP地址
/*来自 时 代 J a v a - nowjava.com*/ //package com.nowjava; import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static void main(String[] argv) throws Exception { System.out.println(getIPAddress()); } public static final String IPADDRESS = "0.0.0.0"; public static String getIPAddress() { String ip = IPADDRESS;/*n o w j a v a . c o m*/ try { String ha = InetAddress.getLocalHost().getHostAddress(); InetAddress[] a = InetAddress.getAllByName(ha); if (a.length == 1) {