import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.HashMap;
import java.util.Map;
/***
* 获取客户机的mac地址和ip地址
*
* @author xiaomage
*
*/
public class GetNetWorkInfo {
/***
* 获取机器的mac地址和ip地址
* @return
*/
public static Map getNetWorkInfo(){
Map map = new HashMap();
try {
//得到IP
InetAddress ia = InetAddress.getLocalHost();
map.put("ip", ia.toString());
//获取网卡,获取地址
byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress();
StringBuffer sb = new StringBuffer("");
for(int i=0; i
if(i!=0) {
sb.append("-");
}
//字节转换为整数
int temp = mac[i]&0xff;
String str = Integer.toHexString(temp);
if(str.length()==1) {
sb.append("0"+str);
}else {
sb.append(str);
}
}
map.put("mac", sb.toString());
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
}