答案 0 :(得分:0)
以下是访问Android中的ARP表以解析IP到Mac地址的代码示例
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;
}