为了账号安全,请及时绑定邮箱和手机立即绑定

通过 IP 获取设备 MAC 地址

通过 IP 获取设备 MAC 地址

天涯尽头无女友 2021-09-03 14:13:28
好吧,在我的应用程序中,我使用一些代码来发现本地网络中所有可访问的设备。现在我想使用本地 ip 地址获取设备的 mac 地址我想要这样的东西: getMacAddress("192.168.1.23")public static String getMacAddress(String ip){    String macAddress = ...    return macAddress;}我发现这个是为了获取我自己的 mac 地址,那么 LAN 中的其余 ips 呢? WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = manager.getConnectionInfo(); String address = info.getMacAddress();
查看完整描述

3 回答

?
qq_花开花谢_0

TA贡献1835条经验 获得超7个赞

/proc/net/arp是本地ARP缓存,它至少有缓存条目(可能是离线的)。


protected String getMacAddress(String ipAddress) {

    try {

        BufferedReader br = new BufferedReader(new FileReader(new File("/proc/net/arp")));

        String line;

        while((line = br.readLine()) != null) {

            if(line.contains(ipAddress)) {

                /* this string still would need to be sanitized */

                return line;

            }

        }

        System.out.println(output);

    } catch (IOException e) {

        e.printStackTrace();

    }

    return null;

}

或者,可以扫描整个本地网段 -


或ARP从本地网络路由器检索缓存。


查看完整回答
反对 回复 2021-09-03
?
蝴蝶不菲

TA贡献1810条经验 获得超4个赞

该功能仅适用于获取您自己的 MAC,即使如此,它对现代 Android 也有严重的限制。您想要的不是 Android 的功能。


查看完整回答
反对 回复 2021-09-03
  • 3 回答
  • 0 关注
  • 209 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信