java获得本机IP

源代码段

package Week9;
import java.net.InetAddress;
public class GetIP_Host {
	public static void main(String[] args) {
		InetAddress a = InetAddress.getLoopbackAddress();
		String hostname = a.getHostName();
		String hostIP = a.getHostAddress();
		System.out.println("主机名:" + hostname + "    IP地址:" + hostIP);
	}
}

你可能感兴趣的:(java获得本机IP)