(Android)如何确定连接到Android热点的设备的IP地址

3

我正在编写一款安卓应用程序,可用于控制其他设备,前提是这些设备连接到我的安卓手机的Wi-Fi热点。但是,我无法确定连接设备的IP地址(例如另一台安卓手机)。因此,我想知道如何确定我Wi-Fi热点中已连接设备的IP地址。谢谢。


这个页面可能会帮助您找到答案。http://android.stackexchange.com/questions/46649/how-to-get-the-information-of-users-connected-to-a-wi-fi-hotspot - Aravindan K
1
但是我能在API方法中确定IP地址吗?我想以自动化的方式完成它。 - user3338304
请在下面的链接上尝试此代码。https://dev59.com/Jmw05IYBdhLWcg3wwEcS#7049074 - Aravindan K
3个回答

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;
    }

0

0

是的,我正在寻找一个API来完成这项工作。 - user3338304
谢谢您的回复,我之前尝试过这篇文章,但是没有成功。 - user3338304
不客气 ;) 但是正如所提到的,没有官方API。如果你想要自己构建API,那么你需要付出很多努力。 - manniL

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接