(android)如何确定android热点中连接设备的ip地址

时间:2014-12-10 17:20:18

标签: android ip wifi

我正在编写一个Android应用程序来控制其他设备,如果其他设备连接到我的Android手机的Wifi热点。但是,我无法确定连接设备的IP地址(比如另一个Android手机)。因此,我想问一个方法来确定我的wifi热点中连接设备的IP地址。提前谢谢

3 个答案:

答案 0 :(得分:1)

您可以尝试this方法获取连接到热点的设备列表。对于pingCmd,请参阅this

public ArrayList<String> getArpLiveIps(boolean onlyReachables) {
            BufferedReader bufRead = null;
            ArrayList<String> result = null;

            try {
                    result = new ArrayList<String>();
                    bufRead = new BufferedReader(new FileReader("/proc/net/arp"));
                    String fileLine;
                    while ((fileLine = bufRead.readLine()) != null) {


                            String[] splitted = fileLine.split(" +");

                              if ((splitted != null) && (splitted.length >= 4)) {

                                    String mac = splitted[3];
                                     if (mac.matches("..:..:..:..:..:..")) {
                                          boolean isReachable = pingCmd(splitted[0]);/**
 * Method to Ping  IP Address    
 * @return true if the IP address is reachable
 */
                                         if (!onlyReachables || isReachable) {
                                                    result.add(splitted[0]);
                                            }
                                    }
                            }
                    }
            } catch (Exception e) {

            } finally {
                    try {
                        bufRead.close();
                    } catch (IOException e) {

                    }
            }

            return result;
    }

答案 1 :(得分:0)

如果你的股票Android Hotspot应用程序没有此选项。使用此应用

https://play.google.com/store/apps/details?id=com.etustudio.android.hotspotmanager

答案 2 :(得分:0)

不幸的是,热点没有正式的API,但你可以使用反射,即使它可能很难。

另请查看IP address of device using phone as access point

相关问题