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";
}
参考:https://www.cnblogs.com/liuyj-vv/p/10177649.html