两天以来,我一直在寻找连接的服务器的MAC地址问题的解决方案。在我的应用程序“远程iTunes DJ和UpNext”中,我需要iTunes PC的媒体访问控制地址来执行WOL功能。
不幸的是,FileReader("/proc/net/arp")函数不再适用于Android10。
我尝试了很多东西,比如:
InetAddress address = socket.getInetAddress();
NetworkInterface network = NetworkInterface.getByInetAddress(address);
byte[] mac = network.getHardwareAddress();...but我得到的结果只有NULL ...
在Google Play中,我找到了像“网络分析器”这样的应用程序,通过这个应用程序,我看到了iTunes服务器PC的MAC地址。
似乎有一种方法可以获取网络中设备的MAC地址。
知道我怎么才能得到MAC地址吗?
谢谢艾尔达尔
发布于 2020-06-04 17:02:47
我用下面的代码找到了一个解决方案:
private static final String IP_CMD = "ip neighbor";
...
BufferedReader reader = null;
try {
    Process ipProc = Runtime.getRuntime().exec(IP_CMD);
    ipProc.waitFor();
    if (ipProc.exitValue() != 0) {
        throw new Exception("Unable to access ARP entries");
    }
    reader = new BufferedReader(new InputStreamReader(ipProc.getInputStream(), "UTF-8"));
    String line;
    while ((line = reader.readLine()) != null) {
        String[] neighborLine = line.split("\\s+");
        // We don't have a validated ARP entry for this case.
        if (neighborLine.length <= 4) {
            continue;
        }
        String ipaddr = neighborLine[0];
        InetAddress addr = InetAddress.getByName(ipaddr);
        if (addr.isLinkLocalAddress() || addr.isLoopbackAddress()) {
            continue;
        }
        String macAddress = neighborLine[4];
        ....https://stackoverflow.com/questions/62073421
复制相似问题