最近在做一个Android项目,需要访问ARP表。要求之一是避免任何需要 root 设备的方法。所以,我的问题是:
有没有办法在不root设备的情况下访问android中的ARP表?
目前我发现大多数方法都使用 /proc/net/arp 来访问 ARP 表,这需要 root 权限,我不确定这是否是唯一的方法。
我可以在没有 root 的情况下访问 ARP 表。这是我的代码:
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)