Android机顶盒取网卡的Mac地址
来源:互联网 发布:编程员工资 编辑:程序博客网 时间:2024/04/28 01:52
android机顶盒上一般有两个网卡,一个有线一个无线,那么在获取mac地址来唯一标识一台终端的时候取那个呢?经过讨论,取有线的Mac地址。但是当前如果我只用的是wifi呢?怎么取有线网卡的mac地址,经过观察settings里面的源码,发现了获取有线网卡mac地址的方法,即使当前机顶盒连接时wifi,如下:
- public String getEth0HW(){
- EthernetManager ethManager = (EthernetManager) getSystemService(Context.ETHERNET_SERVICE);
- String str = ethManager.getEthernetHwaddr(ethManager.getEthernetIfaceName());
- if(null == str){
- str = "null";
- }
- return str ;
- }
/**
* 获取wifi模块的mac地址,即使wifi是关闭的,需要添加权限 ACCESS_WIFI_STATE
* @param context
* @return
*/
public static String getWifiMac(Context context){
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
String mac = info.getMacAddress();
Log.e("","wifi mac : " + mac);
return mac ;
}
- 获取当前连接网络的网卡的mac地址
- private static String parseByte(byte b) {
- String s = "00" + Integer.toHexString(b)+":";
- return s.substring(s.length() - 3);
- }
- /**
- * 获取当前系统连接网络的网卡的mac地址
- * @return
- */
- @SuppressLint("NewApi")
- public static final String getMac() {
- byte[] mac = null;
- StringBuffer sb = new StringBuffer();
- try {
- Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
- while (netInterfaces.hasMoreElements()) {
- NetworkInterface ni = netInterfaces.nextElement();
- Enumeration<InetAddress> address = ni.getInetAddresses();
- while (address.hasMoreElements()) {
- InetAddress ip = address.nextElement();
- if (ip.isAnyLocalAddress() || !(ip instanceof Inet4Address) || ip.isLoopbackAddress())
- continue;
- if (ip.isSiteLocalAddress())
- mac = ni.getHardwareAddress();
- else if (!ip.isLinkLocalAddress()) {
- mac = ni.getHardwareAddress();
- break;
- }
- }
- }
- } catch (SocketException e) {
- e.printStackTrace();
- }
- if(mac != null){
- for(int i=0 ;i<mac.length ;i++){
- sb.append(parseByte(mac[i]));
- }
- return sb.substring(0, sb.length()-1);
- }else{
- return UpdateService.mDefaultMacAddress;
- }
- }
- }
0 0
- Android机顶盒取网卡的Mac地址
- Android机顶盒取网卡的Mac地址
- 用C#取网卡MAC地址
- vb取网卡Mac地址代码
- 在Delphi7内取网卡MAC地址
- 在Windows中取得多个网卡的MAC地址及多个IP地址
- 修改网卡的mac地址
- 获取网卡的mac地址
- 获取网卡的MAC地址
- 读取网卡的MAC地址
- 获取网卡的MAC地址
- 设置网卡的mac地址
- Android TV中获取有线网卡的MAC地址
- WMI技巧-取网卡的MAC地址,CPU,主板,硬盘序列号
- 取网卡地址
- Android机顶盒 获取当前连接网络的Ip地址
- ASP获得网卡的MAC地址
- 如何查找局域网内网卡的MAC地址。
- utf8 和unicode关系
- c++ builder firemonkey 实现填充椭圆
- 开心的金明
- 特殊符号☎▶
- 物资配送路径问题(一)
- Android机顶盒取网卡的Mac地址
- ant + findbugs 安装及实现静态代码检查,并生成HTML检查报告
- 缘聚缘散,皆是缘
- tomcat启动报错,找不到对应的 queue,从而引发内存泄漏
- \u Unicode和汉字转化
- eclipse 中的html 中的中文都是乱码
- 毕业5年决定人的一生-- 大家千万不要错过这篇文章
- 深入理解Java内存模型(二)——重排序
- 后缀自加和后缀自减操作符++ 和--