6

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);
         }
      }
amol rajput
  • 171
  • 1
  • 2
  • 3

2 Answers2

8

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].

Gábor
  • 9,466
  • 3
  • 65
  • 79
5

Android 10 introduces several privacy-related restrictions that disallow apps to access certain information that could be potentially misused for fingerprinting and data collection. One of among them is the restriction on access to /proc/net filesystem on devices that run Android 10 or higher, apps cannot access /proc/net, which includes information about a device's network state. Apps that need access to this information, such as VPNs, should use the NetworkStatsManager or ConnectivityManager class.

The current APIs in Android doesn't allow apps to access the ARP cache. I see a bug is raised in Google issue tracker that is currently in the below status - https://issuetracker.google.com/issues/130103885

Status: Won't Fix (Infeasible) We've passed along your input to our internal teams, who are evaluating it for a future release. We're closing this issue for now, and thanks for sending us your feedback!"

https://developer.android.com/about/versions/10/privacy/changes#proc-net-filesystem

Related thread [ Acccess to /proc/net/tcp in Android Q ] - https://stackoverflow.com/a/58501039/4694013

Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73