2

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();

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

Saran Tunyasuvunakool
  • 1,064
  • 1
  • 9
  • 23

1 Answers1

7

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:

FreeBSD Toolbox diagram

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.

Hrafn
  • 2,867
  • 3
  • 25
  • 44
  • I don't suppose you know of any place with data on which major devices (if any) have any of these functionalities missing? – Saran Tunyasuvunakool Feb 23 '15 at 22:19
  • No sorry haven't seen a list like that around. I can imagine most devices will have it though, since this is a rather basic tool to have. – Hrafn Feb 23 '15 at 22:30
  • I'll add that some devices come bundled with BusyBox, which contains netstat: http://www.busybox.net/downloads/BusyBox.html – Hrafn Feb 24 '15 at 10:10