netstat
netstat copied to clipboard
Proccess is not given in android N
Hello . execuring this netstat is fine with adb shell without root permission and it gives process name but when i try to get processname through shell in y application , the name pf the process is empty . sample result from netstat executed inside application :
D/BBB: Line Proto Recv-Q Send-Q Local Address Foreign Address State Process
D/BBB: Line tcp6 1 0 ::ffff:10.0.2.15:38568 ::ffff:88.99.44.131:80 CLOSE_WAIT
D/BBB: Line tcp6 1 0 ::ffff:10.0.2.15:38567 ::ffff:88.99.44.131:80 CLOSE_WAIT
D/BBB: Line tcp6 0 0 ::ffff:10.0.2.15:48296 ::ffff:119.147.146.168:80 ESTABLISHED
I think probably it will be user permission issue because adb shell's user id(uid) is different from your app's user id(uid) in (Android) Linux. This netstat command can succeed every system call when you run it in your adb shell. But, your app's some system call can fail even though your app runs it through shell. Both of them haven't the same permission. And If you can see it on only Android N system, you should check a Android Developer Blog article. If you can show your code, I will follow it.
I appreciate your response to this issue . The code is nothing particular , the code is as follows :
Process process = Runtime.getRuntime().exec(getFilesDirectory+"/netstat2");
process.waitFor();
Thread.sleep(3000);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = bufferedReader.readLine()) != null) {
Log.d("BBB","Line "+line);
}
I have checked this issue. Android application can't read "/proc" directory except for its own process directory in only Android N system. Because it fail to read other process's /proc directory(/proc/$PID), the process list is empty though netstat command is working in adb shell. If I find another solution, I will share it.
Well , i have found a working solution . instead of packagename i return UID from netstat and from there , there is a command in packagemanager that returns packagename from UID
String packagename = pm.getPackagesForUid(UID)[0];
Good job! Thanks for sharing your solution.