:直接使用win那种获取有可能不准确
//linux下 获取计算机ip:直接使用win那种获取有可能不准确
public Map<String,String> getIpAddress() {
Map<String,String> map = new HashMap<String,String>(5);
try {
//获取所有的网络接口
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
while (allNetInterfaces.hasMoreElements()) {
//遍历每一个网络接口
NetworkInterface netInterface = allNetInterfaces.nextElement();
//若是网路接口是:1回环接口 2虚拟网口 3网口状态为unUser,则跳过
if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
continue;
} else {
//返回和网络接口绑定的所有ip地址
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
System.out.println("网口名称:" + netInterface.getName