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?