【问题标题】:Is the 'netstat' command generically available on Android?'netstat' 命令在 Android 上通常可用吗?
【发布时间】:2015-02-23 18:46:22
【问题描述】:

我目前使用以下代码来获取有关活动网络套接字的一些信息。到目前为止,我已经确认这适用于 Nexus 4 (Jellybeans)、Nexus 5 (Jellybeans、KitKat 和 Lollipop) 和 Sony Xperia 设备 (Jellybeans)。

Process process = Runtime.getRuntime().exec("netstat -n");
process.getOutputStream().close();
BufferedReader reader = new BufferedReader(
        new InputStreamReader(process.getInputStream()));

String line;
while ((line = reader.readline()) != null) {
    // Parse line for required info
}

reader.close();

我可以依靠上面的代码在大多数现实世界的 Android 设备上正常运行吗?

【问题讨论】:

    标签: android netstat


    【解决方案1】:

    Android shell 命令大部分位于设备上的 /system/bin 文件夹中。 Vanilla Android 使用包含 netstat 的 FreeBSD 工具箱,但我不确定您是否可以 100% 确定它会一直存在,因为 OEM 有时会附带不同的工具。这是工具箱中包含的工具的示意图:

    您可以查看source for vanilla Android 以查看哪些版本附带了什么。但就像我说的那样,每个制造商为每个设备提供的产品可能会有所不同。

    【讨论】:

    • 我想你不知道有哪些主要设备(如果有的话)缺少这些功能的数据吗?
    • 不,抱歉还没有看到这样的列表。我可以想象大多数设备都会有它,因为这是一个相当基本的工具。
    • 我会补充一点,一些设备与 BusyBox 捆绑在一起,其中包含 netstat:busybox.net/downloads/BusyBox.html
    猜你喜欢
    • 1970-01-01
    • 2015-05-10
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    相关资源
    最近更新 更多