1、adb shell
2、ifconfig eth1 up //打开eth1 网卡
3、ifconfig eth1 192.168.20.8 //设置eth1静态ip
4、查看网卡信息,已经有eth1网卡信息了:
ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope: Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:420 errors:0 dropped:0 overruns:0 frame:0
TX packets:420 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:48008 TX bytes:48008
eth1 Link encap:Ethernet HWaddr 00:e0:4c:68:00:e5
inet addr:192.168.20.8 Bcast:192.168.20.255 Mask:255.255.255.0
inet6 addr: fe80::2e0:4cff:fe68:e5/64 Scope: Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8456 errors:0 dropped:0 overruns:0 frame:0
TX packets:364 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:912312 TX bytes:19508
eth0 Link encap:Ethernet HWaddr a8:33:15:c1:9e:ca
inet addr:172.16.5.84 Bcast:172.16.5.255 Mask:255.255.255.0
inet6 addr: fe80::aa33:15ff:fec1:9eca/64 Scope: Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:123156 errors:0 dropped:0 overruns:0 frame:0
TX packets:39230 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:88504593 TX bytes:3665312
Interrupt:24
5、现在还无法访问,还需要把eth1的路由添加到eth0
ip route add 192.168.20.0/24 dev eth1 proto static scope link table eth0
现在eth0 和 eth1都可以使用了
代码执行
RootCmd.execRootCmd("ifconfig eth1 up");
RootCmd.execRootCmd("ifconfig eth1 192.168.20.8");
RootCmd.execRootCmd("ip route add 192.168.20.0/24 dev eth1 proto static scope link table eth0");
package com.aimei.meiktv.meiktvvod.utils;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import android.util.Log;
/**
* Android运行linux命令
*/
public final class RootCmd {
public static String execRootCmd(String cmd) {
String result = "";
DataOutputStream dos = null;
DataInputStream dis = null;
try {
Process p = Runtime.getRuntime().exec("su");// 经过Root处理的android系统即有su命令
dos = new DataOutputStream(p.getOutputStream());
dis = new DataInputStream(p.getInputStream());
Log.i(TAG, cmd);
dos.writeBytes(cmd + "\n");
dos.flush();
dos.writeBytes("exit\n");
dos.flush();
String line = null;
while ((line = dis.readLine()) != null) {
Log.d("result", line);
result += line;
}
p.waitFor();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (dos != null) {
try {
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (dis != null) {
try {
dis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
}
网友评论