adb查看设备mac地址信息,设置mac地址

netcfg
下面是实例,可以看到ip和mac地址。

127|root@N1:/ # netcfg
rmnet_data7 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
rmnet_data5 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
rmnet_data6 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
rmnet_data1 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
rmnet_data0 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
rmnet_data4 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
rmnet_data2 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
rmnet_data3 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
rmnet0   UP                                     0.0.0.0/0   0x00000041 00:00:00:00:00:00
r_rmnet_data1 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
r_rmnet_data2 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
r_rmnet_data0 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
r_rmnet_data4 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
r_rmnet_data3 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
r_rmnet_data7 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
r_rmnet_data5 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
r_rmnet_data6 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
r_rmnet_data8 DOWN                                   0.0.0.0/0   0x00000000 00:00:00:00:00:00
dummy0   DOWN                                   0.0.0.0/0   0x00000082 e2:6e:76:42:25:57
wlan0    UP                                     0.0.0.0/0   0x00001003 b4:77:48:03:93:c2
lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:00:00:00
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
p2p0     UP                                     0.0.0.0/0   0x00001003 b6:77:48:03:93:c2
eth0     UP                                192.168.1.21/24  0x00001043 b4:77:48:03:93:c2

经常忘记,直接写下来。
下面是设置eth0

netcfg eth0 down
netcfg etho hwaddr b4:77:48:03:93:c2
netcfg eth0 up

java代码实现:

    static private void setNetMac(String str){
        try{
            //第一步
            executeCMD("netcfg eth0 down");
            executeCMD("netcfg eth0 hwaddr " + str);
            executeCMD("netcfg eth0 up");
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    static public boolean executeCMD(String cmd){
        try {
            Runtime runtime = Runtime.getRuntime();
            Process proc = runtime.exec(cmd);
            proc.waitFor();
            byte[] bytes = new byte[256];
            int size = proc.getErrorStream().read(bytes);
            String stringLog = new String(bytes, 0, size);
            //Log.d("xlm", "executeCMD cmd + " + cmd + ", error :" + stringLog);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

注意可能没有权限。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值