Java 获取AllJoyn所装载设备的IP地址

Java 获取AllJoyn所装载设备的IP地址,java,android,alljoyn,Java,Android,Alljoyn,有什么方法可以获取AllJoyn安装的设备的IP地址吗?服务发布不会持续很长时间,我不能依靠它从DNS记录中读取IP。AllJoyn中是否有返回所安装设备IP地址的API?我目前正在使用Android代码,但没有找到任何接近的代码。谢谢你的帮助。我还没有尝试AllJoyn,但我在android上使用这段代码从eth0端口获取ipaddress;我觉得这对你有帮助- Class<?> SystemProperties = Class.forName("android.os.System

有什么方法可以获取AllJoyn安装的设备的IP地址吗?服务发布不会持续很长时间,我不能依靠它从DNS记录中读取IP。AllJoyn中是否有返回所安装设备IP地址的API?我目前正在使用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");
classsystemproperties=Class.forName(“android.os.SystemProperties”);
方法Method=SystemProperties.getMethod(“get”,新类[]{String.Class});
字符串ip=null;
返回ip=(字符串)方法.invoke(null,“dhcp.eth0.ipaddress”);

最后使用公布的MAC地址作为AP的名称,并通过解析可通过/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;
    }

不是android设备的IP。我的意思是使用AllJoyn框架获取板载设备的IP地址。