获取本地计算机的IP地址和主机名
import java.net.InetAddress; /** 时 代 J a v a 公 众 号 - N o w J a v a . c o m 提供 **/ import java.net.UnknownHostException; public class Main { public static void main(String[] args) { try { InetAddress addr = InetAddress.getLocalHost(); // Get IP Address byte[] ipAddr = addr.getAddress(); // Get hostname String hostname = addr.getHostName(); } catch (UnknownHostException e) { } } }