/**
* 获取本机的Mac地址
* @return
*/
public String getMac() {
InetAddress ia;
byte[] mac = null;
try {
// 获取本地IP对象
ia = InetAddress.getLocalHost();
// 获得网络接口对象(即网卡),并得到mac地址,mac地址存在于一个byte数组中。
mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress();
} catch (Exception e) {
e.printStackTrace();
}
// 下面代码是把mac地址拼装成String
StringBuffer sb = new StringBuffer();
for (int i = 0; i < mac.length; i++) {
if (i != 0) {
sb.append("-");
}
// mac[i] & 0xFF 是为了把byte转化为正整数
String s = Integer.toHexString(mac[i] & 0xFF);
sb.append(s.length() == 1 ? 0 + s : s);
}
// 把字符串所有小写字母改为大写成为正规的mac地址并返回
return sb.toString().toUpperCase();
}

最新文章

  1. How Do Annotations Work in Java?--转
  2. Html_Img元素 设置图片与其他元素横排高度一致
  3. 浮动框控制及切换、banner随机数js
  4. emu1
  5. iOS 定制controller过渡动画 ViewController Custom Transition使用体会
  6. Android系统目录结构
  7. C++ Primer : 第十一章 : 关联容器之关联容器的迭代器和操作
  8. c++中ifstream读文件的问题(关于eof())
  9. BF-KMP 算法
  10. [iOS UI进阶 - 3.1] 触摸事件的传递
  11. HTML入门教程(全套)
  12. 最全SpringMVC具体演示样例实战教程
  13. Eclipse4.4.2手动安装Veloeclipse-2.0.8
  14. makefile知识点归纳的
  15. Centos7.0下将Python更新到Python2.7.13
  16. ArcGIS API for JavaScript 4.2学习笔记[29] 热点(密度)分析——以报警频率为例【使用Geoprocessor类】
  17. 2015 多校联赛 ——HDU5402(模拟)
  18. Python开发——利用正则表达式实现计算器算法
  19. linux 学习笔记 wc命令
  20. Installing Windows Features without Internet

热门文章

  1. Codeforces 702F - T-shirts(平衡树+势能分析)
  2. Codeforces 739D - Recover a functional graph(二分图匹配)
  3. 洛谷 P4749 - [CERC2017]Kitchen Knobs(差分转换+dp,思维题)
  4. R 语言实战-Part 3 笔记
  5. python-django111111111111
  6. 【Linux】非root安装Python3及其包管理
  7. WebRTC网页打开摄像头并录制视频
  8. 点击下拉选择触发事件【c#】
  9. Spring Boot 热启动插件
  10. 如何在 ASP.NET Core 中构建轻量级服务