我正在开发一个安卓应用程序,在那里我需要使用带有接口名的ping命令,没有接口的.Ping命令工作得很好,但是如果我指定了接口名,没有根权限的ping不能在linux终端中使用work.Ping。
我正在尝试下面的命令
pingCommand = "ping -I wlan0 192.168.230.2"; //Does not work
proc = runtime.exec(pingCommand);
pingCommand = "ping 192.168.230.2"; //This does work
proc = runtime.exec(pingCommand);请分享一些解决此问题的方法。
发布于 2016-11-30 19:06:48
我做了一些关于在Android中使用界面的ping的实验,我有以下结论。
1)使用特定接口(例如: wlan0)执行Ping操作需要根用户权限。但是一个指定的手机"HUAWEI NXT-AL 10(Android6.0)“,我可以在没有超级用户权限的情况下使用接口(wlan0)进行ping。
2)对于其他手机(尝试使用Moto G,Micoromax android one),如果root被启用,则允许使用interface ping,否则不允许。
发布于 2016-11-28 22:32:14
你能发布你得到的错误信息吗,以下是在ubuntu上工作的示例代码:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class RuntimeDemo {
public static void main(String args[]) {
String s;
Process p;
try {
p = Runtime.getRuntime().exec("ping -I wlan0 192.168.1.119");
BufferedReader br = new BufferedReader(
new InputStreamReader(p.getInputStream()));
while ((s = br.readLine()) != null)
System.out.println("line: " + s);
p.waitFor();
System.out.println ("exit: " + p.exitValue());
p.destroy();
} catch (Exception e) {}
}
}发布于 2021-01-30 09:21:34
问题是,在Android中,命令是“/my_url_or_ip/bin/ping system”,这就是为什么你找不到它的原因。
https://stackoverflow.com/questions/40846291
复制相似问题