"netstat"命令通常可在Android上使用吗? [英] Is the 'netstat' command generically available on Android?

查看:63
本文介绍了"netstat"命令通常可在Android上使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用以下代码来获取有关活动网络套接字的一些信息.到目前为止,我已经确认它可以在Nexus 4(豆形软糖),Nexus 5(豆形软糖,奇巧和棒棒糖)和Sony Xperia设备(豆形软糖)上使用.

I currently use the following code to obtain some information on active network sockets. So far I've confirmed that this works on Nexus 4 (Jellybeans), Nexus 5 (Jellybeans, KitKat and Lollipop) and a Sony Xperia device (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设备上正常运行吗?

Can I rely on the the above code to function properly on the majority of real-world Android devices out there?

推荐答案

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

The Android shell commands are, most of them, found in the /system/bin folder on the device. Vanilla Android uses the FreeBSD Toolbox that contains netstat, but I'm not sure if you can be 100% sure that it will always be around since the OEM's sometimes ship with different tools. Here is a diagram of the tools contained in the toolbox:

您可以查看适用于香草Android,以查看什么版本附带了什么.但是就像我说的那样,每个制造商随设备附带的物品可能有所不同.

You can go over the source for vanilla Android to see what ships with what version. But like I said, there might be differences in what each manufacturer ships with each device.

这篇关于"netstat"命令通常可在Android上使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆