获取使用 AllJoyn 载入的设备的 IP 地址

Get the IP address of the device onboarded with AllJoyn

有什么方法可以获取已加入 AllJoyn 的设备的 IP 地址?服务发布不会持续很长时间,我不能依赖它从 DNS 记录中读取 IP。 AllJoyn 中是否有一个 API returns 设备的 IP 地址?我目前正在使用 Android 代码,但没有找到任何接近的代码。感谢您的帮助。

我还没有用 AllJoyn 试过,但我在 android 上使用这段代码从 eth0 端口获取 ipaddress;认为这可能对您有所帮助 -

Class<?> SystemProperties = Class.forName("android.os.SystemProperties");
    Method method = SystemProperties.getMethod("get", new Class[]{String.class});
    String ip = null;
    return  ip = (String) method.invoke(null,"dhcp.eth0.ipaddress");

最终使用通告为 AP 名称的 MAC 地址并通过解析可通过 /proc/net/arp 文件访问的 ARP 缓存进行反向查找。

if (device.getAPWifiInfo() != null) {
                String mac = device.getAPWifiInfo().getSSID();
                String split_mac[] = mac.split(" ");
                Log.i(TAG, "Mac from ssid is " + split_mac[1]);
                mac = split_mac[1];
                ip = getIPfromMac(mac);
                Log.i(TAG, "IP is " + ip);
}



   //returns the ip and takes mac address as parameter

   public static String getIPfromMac(String mac) {
        if (mac == null)
            return null;
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader("/proc/net/arp"));
            String line;
            while ((line = br.readLine()) != null) {
                String[] splitted = line.split(" +");
                if (splitted != null && splitted.length >= 4 && mac.equalsIgnoreCase(splitted[3])) {
                    // Basic sanity check
                    String ip = splitted[0];
                    return ip;
                }

            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }