Tonfay
2014-07-09 14:02:24
[个人笔记]Java获取本机MAC地址
//获取网卡,获取地址 InetAddress ia = InetAddress.getLocalHost(); System.out.println(ia); byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress(); System.out.println("mac数组长度:"+mac.length); StringBuffer sb = new StringBuffer(""); for(int i=0; i<mac.length; i++) { if(i!=0) { sb.append("-"); } //字节转换为整数 int temp = mac[i]&0xff; String str = Integer.toHexString(temp); System.out.println("每8位:"+str); if(str.length()==1) { sb.append("0"+str); }else { sb.append(str); } } System.out.println("本机MAC地址:"+sb.toString().toUpperCase());
ps:管理请改为0牛币
猜你喜欢
请下载代码后再发表评论



wjh12345654321 LV14
2021年11月11日
pdd1234 LV2
2021年9月1日
jlxxfjc LV1
2021年9月1日
itcaizhe LV9
2021年7月26日
Hadoop_CPU LV6
2020年12月24日
jachyn LV6
2020年9月9日
邈话12123 LV9
2020年8月8日
Thomas杨
2020年3月8日
暂无贡献等级
wywtiao LV6
2019年12月3日
H15029260755 LV1
2019年11月30日