日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

java查看蓝牙mac地址_Java如何获取主机的MAC地址?

發(fā)布時(shí)間:2024/9/27 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java查看蓝牙mac地址_Java如何获取主机的MAC地址? 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

以前,為了獲取MAC地址,我們需要使用本機(jī)代碼作為解決方案。在JDK 1.6中,java.net.NetworkInterface類中添加了一個(gè)新方法,該方法為getHardwareAddress()。package?org.nhooo.example.network;

import?java.net.InetAddress;

import?java.net.NetworkInterface;

import?java.net.SocketException;

import?java.net.UnknownHostException;

public?class?MacAddress?{

public?static?void?main(String[]?args)?{

try?{

// InetAddress地址= InetAddress.getLocalHost();

InetAddress?address?=?InetAddress.getByName("192.168.42.26");

/*

*?Get?NetworkInterface?for?the?current?host?and?then?read

*?the?hardware?address.

*/

NetworkInterface?ni?=??NetworkInterface.getByInetAddress(address);

if?(ni?!=?null)?{

byte[]?mac?=?ni.getHardwareAddress();

if?(mac?!=?null)?{

/*

*?Extract?each?array?of?mac?address?and?convert?it

*?to?hexadecimal?with?the?following?format

*?08-00-27-DC-4A-9E.

*/

for?(int?i?=?0;?i?

System.out.format("%02X%s",

mac[i],?(i?

}

}?else?{

System.out.println("Address?doesn't?exist?or?is?not?"?+

"accessible.");

}

}?else?{

System.out.println("Network?Interface?for?the?specified?"?+

"address?is?not?found.");

}

}?catch?(UnknownHostException?|?SocketException?e)?{

e.printStackTrace();

}

}

}

總結(jié)

以上是生活随笔為你收集整理的java查看蓝牙mac地址_Java如何获取主机的MAC地址?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。