Reputation: 126
I got the program for Wifi tethering which i got a open (non secured) hot spot in Android. I like to view the details of client (SSID and IP address) connected to my hotspot. I used SocketAddress socketid=socket.getLocalSocketAddress(); and also used
public void getLocalIpAddressString() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
// return inetAddress.getHostAddress().toString();
Toast.makeText(getApplicationContext(), inetAddress.getHostAddress().toString(),
Toast.LENGTH_SHORT).show();
}
}
}
} catch (Exception ex) {
Log.e("IPADDRESS", ex.toString());
}
// return null;
}
These will return only the local IP but can you please help me in getting the IP address of client connected to my Wifi Hotspot. Thank you.
Upvotes: 1
Views: 3364
Reputation: 126
Finally I got the response for getting the Client IP connected to my hotspot. The code below will track the Mac and IP changes each time a new client is added to my network
public void getClientList() {
int macCount = 0;
BufferedReader br = null;
try {
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) {
// Basic sanity check
String mac = splitted[3];
if (mac.matches("..:..:..:..:..:..")) {
macCount++;
ClientList.add("Client(" + macCount + ")");
IpAddr.add(splitted[0]);
HWAddr.add(splitted[3]);
Device.add(splitted[5]);
Toast.makeText(
getApplicationContext(),
"Mac_Count " + macCount + " MAC_ADDRESS "
+ mac, Toast.LENGTH_SHORT).show();
for (int i = 0; i < splitted.length; i++)
System.out.println("Addressssssss "
+ splitted[i]);
}
}
}
Upvotes: 5
Reputation: 1382
you searched in java.net? It is also listed in the android dev...
Upvotes: 0