private String getGateWay() {
String[] arr;
try {
Process process = Runtime.getRuntime().exec("ip route list table 0");
String data = null;
BufferedReader ie = new BufferedReader(new InputStreamReader(process.getErrorStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String string = in.readLine();
arr = string.split("\\s+");
return arr[2];
} catch (IOException e) {
e.printStackTrace();
}
return "error";
}
android 获取网关ip
最新推荐文章于 2025-09-11 17:18:42 发布
本文介绍了一段用于在Java中获取设备当前使用的网关IP地址的代码。通过执行ip route list table 0命令并解析其输出,该方法能够从返回的数据中抽取网关IP。适用于需要在网络编程中快速定位网关地址的场景。
2万+

被折叠的 条评论
为什么被折叠?



