找到连接到同一Wifi网络的所有设备的MAC地址 [英] Find the MAC address of all devices connected to the same Wifi network

查看:2213
本文介绍了找到连接到同一Wifi网络的所有设备的MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个软件来检查哪些设备连接到我的家庭网络,并且每10分钟左右返回一个设备的MAC地址列表。

I'm trying to build a software that checks what devices are connected to my home network and return a list of those device's MAC address every 10 minutes or so.

我的方法是ping网络上所有可能的IP地址,然后调用arp -a。

My approach was to ping all of the possible IP addresses on the network and call "arp -a" afterwards.

以下代码用于查找设备是否在IP地址上注册,但我不知道如何从中获取MAC地址。

The following code works to find if a device is registered on an IP address, but I don't know how to get the MAC address from this.

try {
            String currentIP = InetAddress.getLocalHost().toString();
            String subnet = getSubnet(currentIP);
            System.out.println("subnet: " + subnet);

            for (int i=1;i<254;i++){

                String host = subnet + i;
                System.out.println("Checking :" + host);

                if (InetAddress.getByName(host).isReachable(timeout)){
                    System.out.println(host + " is reachable");
                    try {
                        Socket connected = new Socket(subnet, port);
                    }
                    catch (Exception s) {
                        System.out.println(s);
                    }
                }
            }
        }
        catch(Exception e){
            System.out.println(e);
        }

有什么建议吗?

推荐答案

你盲目地假设IPV4,这些日子已经不再合理了。

You're blindly assuming IPV4, which is not so reasonable anymore these days.

而你正试图挖掘路由器和接入点首先没有充分理由披露的信息(至少不是那些不会将自己认证为具有对路由器或接入点管理页面的访问权限的管理员的机器人) )。

And you're trying to dig out information that routers and access points have no good reason for disclosing in the first place (at least not to robots who won't authenticate themselves as an admin with access rights to the router's or access point's admin page).

这篇关于找到连接到同一Wifi网络的所有设备的MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆