Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission Denied for access /proc/net/arp ARP table in Android 10

Tags:

android

Using ARP table we can access IP and MAC of hotspot connected devices in Android 9 and earlier versions. Now from Android 10 permission denied for the same. Kindly suggest how can I access IP and MAC address of connected devices in Android 10. Below Code working in up-to Android 9 Version but not work in Android 10.

   BufferedReader br = new BufferedReader(new FileReader("/proc/net/arp"));
   String line;
   while ((line = br.readLine()) != null) {
        String[] clientInfo = line.split(" +");
        if(!clientInfo[3].equalsIgnoreCase("type")) {
               String mac = clientInfo[3];
               String ip = clientInfo[0];
               textView.append("\n\nip: " + ip + " Mac: " + mac);
               Log.d("IP : ", ip);
               Log.d("Mac : ", mac);
         }
      }
like image 338
amol rajput Avatar asked Dec 31 '22 00:12

amol rajput


1 Answers

Run the ip neigh show command and process its output:

  val runtime = Runtime.getRuntime()
  val proc = runtime.exec("ip neigh show")
  proc.waitFor()
  val reader = BufferedReader(InputStreamReader(proc.inputStream))

You split the lines the same way, IP is [0], MAC is [4].

like image 108
Gábor Avatar answered Apr 30 '23 12:04

Gábor