java自动获取电脑ip和MAC地址

250次阅读
没有评论

共计 379 个字符,预计需要花费 1 分钟才能阅读完成。

InetAddress ip = InetAddress.getLocalHost();

System.out.println("IP:"+ip);

NetworkInterface network = NetworkInterface.getByInetAddress(ip);

byte[] mac = network.getHardwareAddress();

StringBuilder sb = new StringBuilder();

for (int i = 0; i < mac.length; i++) {sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));

}

String hostMac=sb.toString();

System.out.println("Current MAC address : "+hostMac);
正文完
 
alecctv
版权声明:本站原创文章,由 alecctv 2019-08-23发表,共计379字。
转载说明:除特殊说明外本站文章皆由ooly.cc发布,转载请注明出处。
评论(没有评论)
验证码