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;
}
注意可能没有权限。