android擷取mac地址方法,android擷取mac

來源:互聯網
上載者:User

android擷取mac地址方法,android擷取mac

http://www.cnblogs.com/xioapingguo/p/4037513.html 

網上找的,記錄一下

public static String getMacAdress(){        WifiManager wifi = (WifiManager) sContext.getSystemService(Context.WIFI_SERVICE);          WifiInfo info = wifi.getConnectionInfo();          return info.getMacAddress();    }

記得加入許可權<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>


android怎擷取乙太網路mac地址

本文講述無線網和乙太網路mac地址擷取的方法: 1.乙太網路擷取mac地址 因為機頂盒系統是linux核心的,假設ethernet是eth0,那麼可以從以下檔案中讀取相關資訊:/sys/class/net/eth0/address方法1: public static String loadFileAsString(String filePath) throws java.io.IOException{ StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(new FileReader(filePath)); char[] buf = new char[1024]; int numRead=0; while((numRead=reader.read(buf)) != -1){ String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); } reader.close(); return fileData.toString();}/** Get the STB MacAddress*/public String getMacAddress(){ try { return loadFileAsString("/sys/class/net/eth0/address") .toUpperCase().substring(0, 17); } catch (IOException e) { e.printStackTrace(); return null; }}方法2:NetworkInterface NIC = NetworkInterface.getByName("eth0"); byte[] buf = NIC.getHardwareAddress(); for (int i = 0; i < buf.length; i++) { mac = mac + byteHEX(buf);}if (mac != null && !"".equals(mac)) {}2.wifi擷取mac和ip首先要在manifest.xml檔案中添加許可權: <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>擷取mac的代碼如下WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); return info.getMacAddress();擷取Ip的代碼public String getLocalIpAddress() { try { for (Enumeration<NetworkInterface> en = NetworkInterface .getNetworkInterfaces(); en.hasMoreElements();) { Net......餘下全文>>
 
怎查看Android手機的Mac地址?

很簡單,在設定裡進入WLAN設定,再按手機menu鍵,螢幕下方出現小介面有進階,進入進階,裡面可以看到MAC地址 或者設定裡,進入關於手機
,然後選硬體資訊,裡面也可以看到MAC地址,這個方法同樣適用於其它的Android平台的手機
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.