public String doEthernetShare() { String result = "Failure"; DataOutputStream dataOutputStream = null; BufferedReader errorStream = null; String networkType = getNetworkType(); try { MyLog("doEthernetShare.networkType=" + networkType); Process process = Runtime.getRuntime().exec("su"); dataOutputStream = new DataOutputStream(process.getOutputStream()); String commandStr = "mount -o rw,remount / " + " \n" + "mount -o rw,remount /system " + " \n" + "mkdir -p /var/lib/misc/" + " \n" + "touch /var/lib/misc/udhcpd.leases" + " \n" + "echo 0 > /proc/sys/net/ipv4/ip_forward" + " \n" + "busybox ifconfig eth0 up" + " \n" + "busybox ifconfig eth0 192.168.1.1 netmask 255.255.255.0" + " \n" + "/system/bin/iptables -t nat -A natctrl_nat_POSTROUTING -o " + networkType + " -j MASQUERADE" + " \n" + "/system/bin/iptables -A natctrl_FORWARD -i " + networkType + " -o eth0 -m state --state ESTABLISHED,RELATED -g natctrl_tether_counters" + " \n" + "/system/bin/iptables -A natctrl_FORWARD -i eth0 -o " + networkType + " -m state --state INVALID -j DROP" + " \n" + "/system/bin/iptables -A natctrl_FORWARD -i eth0 -o " + networkType + " -g natctrl_tether_counters" + " \n" + "/system/bin/iptables -A natctrl_tether_counters -i eth0 -o " + networkType + " -j RETURN" + " \n" + "/system/bin/iptables -A natctrl_tether_counters -i " + networkType + " -o eth0 -j RETURN" + " \n" + "/system/bin/iptables -D natctrl_FORWARD -j DROP" + " \n" + "/system/bin/iptables -A natctrl_FORWARD -j DROP" + " \n" + "ip route add 192.168.1.0/24 dev eth0 table local_network proto static scope link" + " \n" + "echo 1 > /proc/sys/net/ipv4/ip_forward" + " \n" + "busybox1.11 udhcpd -fS /etc/udhcpd.conf" + " \n" ; dataOutputStream.write(commandStr.getBytes(Charset.forName("utf-8"))); dataOutputStream.flush(); dataOutputStream.writeBytes("exit\n"); dataOutputStream.flush(); process.waitFor(); errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream())); String msg = ""; String line; // 读取命令的执行结果 while ((line = errorStream.readLine()) != null) { msg += line; } MyLog("msg" +msg); result = msg; } catch (Exception e) { Log.e(TAG_AZ, e.getMessage(), e); } finally { try { if (dataOutputStream != null) { dataOutputStream.close(); } if (errorStream != null) { errorStream.close(); } } catch (IOException e) { Log.e(TAG_AZ, e.getMessage(), e); } } return result; }