问题描述
我获得了 Wifi 网络共享程序,我在 Android 中获得了一个开放(非安全)热点.我喜欢查看连接到我的热点的客户端(SSID 和 IP 地址)的详细信息.我用 SocketAddress socketid=socket.getLocalSocketAddress();并且还使用了
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; }
这些只会返回本地 IP,但您能帮我获取连接到我的 Wifi 热点的客户端的 IP 地址吗?谢谢.
推荐答案
最后我得到了将客户端 IP 连接到我的热点的响应.每次将新客户端添加到我的网络时,下面的代码将跟踪 Mac 和 IP 的变化
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]); } } }
其他推荐答案
问题描述
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.
推荐答案
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]); } } }
其他推荐答案
you searched in java.net? It is also listed in the android dev...