OOLY BLOG

柳絮纷飞
hey!

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

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);
转载文章请注明出处 | 当前页面:OOLY BLOG » java自动获取电脑ip和MAC地址

评论

captcha
请输入验证码