Transferred from: http://blog.csdn.net/beijingshi1/article/details/9119297
Recently developed a project, encountered a problem, in the case of mobile phone hotspot, want to get which device has been connected on the Android phone open hotspot.
After Google,baidu, no answer was found.
Finally remembered in the foreign forum downloaded an AP Demo, looked at the source code, and finally found a solution to the problem.
As follows: This method is certainly familiar to the Linux developers think of the way, with the re file manager to "/proc/net/arp", in a look, found the connection hotspot device information is here, including Mac IP, etc.
Private Arraylist<string> Getconnectedip () {
arraylist<string> Connectedip = new arraylist<string> ();
try {
BufferedReader br = new BufferedReader (New FileReader (
"/proc/net/arp"));
String Line;
while (line = Br.readline ()) = null) {
string[] splitted = line.split ("+");
if (splitted! = null && splitted.length >= 4) {
String IP = splitted[0];
Connectedip.add (IP);
}
}
} catch (Exception e) {
E.printstacktrace ();
}
return CONNECTEDIP;
}
Call Method:
arraylist<string> Connectedip = Getconnectedip ();
Resultlist = new StringBuilder ();
for (String Ip:connectedip) {
Resultlist.append (IP);
Resultlist.append ("\ n");
}
System.out.print (resultlist);
over~~~~
2. Android gets information about devices connected to a mobile hotspot