我正在编写一款安卓应用程序,可用于控制其他设备,前提是这些设备连接到我的安卓手机的Wi-Fi热点。但是,我无法确定连接设备的IP地址(例如另一台安卓手机)。因此,我想知道如何确定我Wi-Fi热点中已连接设备的IP地址。谢谢。
我正在编写一款安卓应用程序,可用于控制其他设备,前提是这些设备连接到我的安卓手机的Wi-Fi热点。但是,我无法确定连接设备的IP地址(例如另一台安卓手机)。因此,我想知道如何确定我Wi-Fi热点中已连接设备的IP地址。谢谢。
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;
}
https://play.google.com/store/apps/details?id=com.etustudio.android.hotspotmanager
很不幸的是,热点没有官方的API,但你可以使用反射,尽管这可能有些困难。
此外,请查看使用手机作为接入点的设备的IP地址