Java获取本地IP和计算机名

package com.bjsxt.base.bhz.nio.test;


import java.net.InetAddress;
import java.net.UnknownHostException;


public class Test {
public static void main(String[] args) {
try {
InetAddress addr = InetAddress.getLocalHost();
String ip ,address;//获得本机IP
ip = ip=addr.getHostAddress().toString();
address=addr.getHostName().toString();
System.out.println(ip+"  "+address);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}

你可能感兴趣的:(Java获取本地IP和计算机名)