0

I want to find the devices with mac address from ARP table but in android 11 we can't access ARP table

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 26 '22 at 11:28

1 Answers1

0

Try this:

string GetMACAddressviaIP(string ipAddr)
{
    string result = "";
    ostringstream ss;
    ss << "/proc/net/arp";
    string loc = ss.str();

    ifstream in(loc);
    if(!in)
    {
        printf("open %s failed\n",loc.c_str());
        return result;
    }

    string line;
    while(getline(in, line)){
        if(strstr(line.c_str(), ipAddr.c_str()))
        {
            const char *buf = strstr(line.c_str(), ":") - 2;
            int counter = 0;
            stringstream ss;
            while(counter < 17)
            {
                ss << buf[counter];
                counter++;
            }
            result = ss.str();
        }
    }

    return result;
}

If this doesn't work, read more about it here: access ARP table without root in Android

  • 1
    Thanks for you response, we can't access arp table in android 11. so how to get macAddress without arp table? java.io.FileNotFoundException: /proc/net/arp: open failed: EACCES (Permission denied) – presita jadav Jan 28 '22 at 13:18