3

i am writing an android app to control other devices if other devices is connected to my android phone's Wifi hotspot. However, i am unable to determine the ip address of the connected devices (say another android phone). Therefore, i am asking a way to determine the ip address of connected devices in my wifi hotspot. Thank you in advance

user3338304
  • 291
  • 2
  • 4
  • 5

3 Answers3

1

You can try this method for getting the list of devices connected to your hotspot. for pingCmd refer 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;
    }
Rishi Pandey
  • 154
  • 11
0

If your stock Android Hotspot app does not have this option. Use this app

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

Mukul Shukla
  • 123
  • 2
  • 12
0

Unfortunately there is no official API for the hotspot, but you could use reflection, even though it might be difficult.

Also check out IP address of device using phone as access point

Community
  • 1
  • 1
manniL
  • 7,157
  • 7
  • 46
  • 72