当我的手机处于 Wi-Fi 网络共享模式时,有什么方法可以获取连接的 MAC 地址列表?
问问题
19460 次
4 回答
9
首先,您必须有一个根设备。完成后,只需阅读dnsmasq.leases文件。通常它位于:/data/misc/dhcp/dnsmasq.leases。文件的结构非常简单——每一行都是连接用户的摘要。摘要有几个字段,包括 MAC。我没有找到没有 root 的可能获得 MAC。如果我错了,请纠正我。
于 2012-04-18T20:15:47.503 回答
7
读取/proc/net/arp
将提供在过去 60 秒内与设备通信的静态和 DHCP 客户端的信息(配置在我手机上的无线网络接口的位置)/proc/sys/net/ipv4/neigh/wl0.1/gc_stale_time
。wl0.1
它也适用于非 root 用户。
于 2013-03-29T12:05:20.373 回答
1
@SuppressWarnings("ConstantConditions")
public static String getClientMacByIP(String ip)
{
String res = "";
if (ip == null)
return res;
String flushCmd = "sh ip -s -s neigh flush all";
Runtime runtime = Runtime.getRuntime();
try
{
runtime.exec(flushCmd,null,new File("/proc/net"));
}
BufferedReader br;
try
{
br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null)
{
String[] sp = line.split(" +");
if (sp.length >= 4 && ip.equals(sp[0]))
{Assistance.Log(sp[0]+sp[2]+sp[3],ALERT_STATES.ALERT_STATE_LOG);
String mac = sp[3];
if (mac.matches("..:..:..:..:..:..") && sp[2].equals("0x2"))
{
res = mac;
break;
}
}
}
br.close();
}
catch (Exception e)
{}
return res;
}
//------------------------------------------------ --------
@SuppressWarnings("ConstantConditions")
public static String getClientIPByMac(String mac)
{
String res = "";
if (mac == null)
return res;
String flushCmd = "sh ip -s -s neigh flush all";
Runtime runtime = Runtime.getRuntime();
try
{
runtime.exec(flushCmd,null,new File("/proc/net"));
}
BufferedReader br;
try
{
br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null)
{
String[] sp = line.split(" +");
if (sp.length >= 4 && mac.equals(sp[3]))
{
String ip = sp[0];
if (ip.matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}") && sp[2].equals("0x2"))
{
res = ip;
break;
}
}
}
br.close();
}
catch (Exception e)
{}
return res;
}
于 2016-11-10T14:36:14.590 回答
0
public static ArrayList<String> getConnectedDevicesMac()
{
ArrayList<String> res = new ArrayList<String>();
//NetManager.updateArpFile();
BufferedReader br;
try
{
br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
line = br.readLine();
while ((line = br.readLine()) != null)
{
String[] sp = line.split(" +");
if (sp[3].matches("..:..:..:..:..:.."))
res.add(sp[3]);
}
br.close();
}
catch (Exception e)
{}
return res;
}
于 2016-11-12T18:09:07.323 回答