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
3
- This page may help you to find your answer. android.stackexchange.com/questions/46649/…Aravindan K– Aravindan K2014-12-10 17:32:34 +00:00Commented Dec 10, 2014 at 17:32
- 1But can i determine the ip in api method?? i would like to do it in automatically wayuser3338304– user33383042014-12-10 17:45:14 +00:00Commented Dec 10, 2014 at 17:45
- Try this code on the below link. stackoverflow.com/a/7049074/3847529Aravindan K– Aravindan K2014-12-10 17:52:08 +00:00Commented Dec 10, 2014 at 17:52
Add a comment |
3 Answers
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; } Comments
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
Comments
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
3 Comments
user3338304
Yes, i am looking for an api to perform the job done
user3338304
Thanks for your reply, i actually try this post before but not work
TheAlexLichter
Your're welcome ;) But as mentioned, there is no official API. You'll need a lot of effort to build your own if you want so.