请问如何获取系统路由表信息。

sevenzhy 2011-06-30 10:45:06
hi~ 大大们,请问有API可疑获取系统路由表信息吗?

或者是否可以通过Runtime.getRuntime().exec("busybox route")之类的操作来读取?


怎么实现会简单些呢?
...全文
663 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssh_hkp 2011-08-11
  • 打赏
  • 举报
回复
怎么解决的,能说一下方法吗?谢谢。。。
[Quote=引用 4 楼 sevenzhy 的回复:]
呃。我试了一下, device上可以成功,但是用Emulator就报了上面的exception.

不过问题算是解决啦。非常感谢!
[/Quote]
fontlose 2011-06-30
  • 打赏
  • 举报
回复
可以使用busybox route


try {
// Executes the command.
Process process = Runtime.getRuntime().exec("busybox route");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
// Waits for the command to finish.
process.waitFor();
return output.toString(); //获得输出
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}




fontlose 2011-06-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 sevenzhy 的回复:]

呃。我试了一下, device上可以成功,但是用Emulator就报了上面的exception.

不过问题算是解决啦。非常感谢!
[/Quote]
谢谢 接分 :)
sevenzhy 2011-06-30
  • 打赏
  • 举报
回复
呃。我试了一下, device上可以成功,但是用Emulator就报了上面的exception.

不过问题算是解决啦。非常感谢!
fontlose 2011-06-30
  • 打赏
  • 举报
回复
我试过可以获取得到 不用什么权限 你直接adb shell busybox route有显示吗?
sevenzhy 2011-06-30
  • 打赏
  • 举报
回复
谢谢你提供的方案,我使用这个方法的时候,碰到如下异常:

06-30 05:35:05.182: ERROR/AndroidRuntime(327): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.David/com.android.David.LogTest1Activity}: java.lang.RuntimeException: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null


06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.lang.RuntimeException: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null

06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.io.IOException: Error running exec(). Command: [busybox, route] Working Directory: null Environment: null

06-30 05:35:05.182: ERROR/AndroidRuntime(327): Caused by: java.io.IOException: Permission denied

请问这个操作需要什么permission呢?

80,492

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧