public static void main(String[] args) {
try {
String ip;//IP地址
String address;//计算机名称
InetAddress addr = InetAddress.getLocalHost();
ip=addr.getHostAddress();
address=addr.getHostName();
System.out.println("计算机名称:"+address+" IP地址:"+ip);
} catch (Exception e) {
e.printStackTrace();
}
}