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

2 Answers 2

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

3
  • 2
    "ip neigh show" doesn't seem to work anylonger on Android 11 devices (and app targets SDK 30 or higher).
    – Dieter27
    Feb 11, 2021 at 15:08
  • Bother, cat and mouse. I'm still on 10 with my phone but I use it actively in an app of mine...
    – Gábor
    Feb 14, 2021 at 12:00
  • Any solution for target 30? @Dieter27D Mar 9, 2022 at 6:48
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

1
  • Why Termux app still can execute these calls?
    – Vygintas B
    Feb 14, 2022 at 8:20

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.