最新连接设备列表android热点

最新连接设备列表android热点,android,arp,hotspot,Android,Arp,Hotspot,我使用以下代码读取连接的设备ip地址 但我得到的是错误的列表,即列表显示了连接到热点但当前断开连接的早期设备。 有没有其他方法可以更新列表。或者如何刷新/proc/net/arp文件以获取最新列表 也请阅读与linux上的arp相关的内容,但没有找到解决方法。这对我来说很有用,它将显示没有连接的设备及其mac地址 public int getClientList() { int macCount = 0; BufferedReader br = null; String

我使用以下代码读取连接的设备ip地址 但我得到的是错误的列表,即列表显示了连接到热点但当前断开连接的早期设备。 有没有其他方法可以更新列表。或者如何刷新/proc/net/arp文件以获取最新列表


也请阅读与linux上的arp相关的内容,但没有找到解决方法。

这对我来说很有用,它将显示没有连接的设备及其mac地址

 public int getClientList() {
    int macCount = 0;
    BufferedReader br = null;
    String flushCmd = "sh ip -s -s neigh flush all";
    Runtime runtime = Runtime.getRuntime();
    try {
        runtime.exec(flushCmd, null, new File("/proc/net"));
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        br = new BufferedReader(new FileReader("/proc/net/arp"));
        String line;
        while ((line = br.readLine()) != null) {
            String[] splitted = line.split(" +");
            if (splitted != null) {
                // Basic sanity check
                String mac = splitted[3];
                System.out.println("Mac : Outside If " + mac);
                if (mac.matches("..:..:..:..:..:..")) {
                    macCount++;
               /* ClientList.add("Client(" + macCount + ")");
                IpAddr.add(splitted[0]);
                HWAddr.add(splitted[3]);
                Device.add(splitted[5]);*/
                    System.out.println("Mac : " + mac + " IP Address : " + splitted[0]);
                    System.out.println("Mac_Count  " + macCount + " MAC_ADDRESS  " + mac);
                    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]);*/

            }
        }
    } catch (Exception e) {

    }
    return macCount;
}
public int getClientList(){
int macCount=0;
BufferedReader br=null;
字符串flushCmd=“sh ip-s-s neigh flush all”;
Runtime=Runtime.getRuntime();
试一试{
runtime.exec(flushCmd,null,新文件(“/proc/net”);
}捕获(IOE异常){
e、 printStackTrace();
}
试一试{
br=新的BufferedReader(新的文件读取器(“/proc/net/arp”);
弦线;
而((line=br.readLine())!=null){
String[]splitted=line.split(“+”);
如果(已拆分!=null){
//基本健康检查
字符串mac=splitted[3];
System.out.println(“Mac:如果“+Mac”,则为外部);
如果(mac.matches(“…:”)){
macCount++;
/*添加(“客户端(“+macCount+”);
IpAddr.add(拆分为[0]);
HWAddr.add(拆分[3]);
设备。添加(拆分[5])*/
System.out.println(“Mac:+Mac+”IP地址:“+splitted[0]);
System.out.println(“Mac_计数”+macCount+“Mac_地址”+Mac);
Toast.makeText(
getApplicationContext(),
“Mac_计数”+Mac计数+“Mac_地址”
+mac,Toast.LENGTH_SHORT).show();
}
/*对于(int i=0;i

试试这个

这对我来说很有效,它将显示连接的设备数量及其mac地址

 public int getClientList() {
    int macCount = 0;
    BufferedReader br = null;
    String flushCmd = "sh ip -s -s neigh flush all";
    Runtime runtime = Runtime.getRuntime();
    try {
        runtime.exec(flushCmd, null, new File("/proc/net"));
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        br = new BufferedReader(new FileReader("/proc/net/arp"));
        String line;
        while ((line = br.readLine()) != null) {
            String[] splitted = line.split(" +");
            if (splitted != null) {
                // Basic sanity check
                String mac = splitted[3];
                System.out.println("Mac : Outside If " + mac);
                if (mac.matches("..:..:..:..:..:..")) {
                    macCount++;
               /* ClientList.add("Client(" + macCount + ")");
                IpAddr.add(splitted[0]);
                HWAddr.add(splitted[3]);
                Device.add(splitted[5]);*/
                    System.out.println("Mac : " + mac + " IP Address : " + splitted[0]);
                    System.out.println("Mac_Count  " + macCount + " MAC_ADDRESS  " + mac);
                    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]);*/

            }
        }
    } catch (Exception e) {

    }
    return macCount;
}
public int getClientList(){
int macCount=0;
BufferedReader br=null;
字符串flushCmd=“sh ip-s-s neigh flush all”;
Runtime=Runtime.getRuntime();
试一试{
runtime.exec(flushCmd,null,新文件(“/proc/net”);
}捕获(IOE异常){
e、 printStackTrace();
}
试一试{
br=新的BufferedReader(新的文件读取器(“/proc/net/arp”);
弦线;
而((line=br.readLine())!=null){
String[]splitted=line.split(“+”);
如果(已拆分!=null){
//基本健康检查
字符串mac=splitted[3];
System.out.println(“Mac:如果“+Mac”,则为外部);
如果(mac.matches(“…:”)){
macCount++;
/*添加(“客户端(“+macCount+”);
IpAddr.add(拆分为[0]);
HWAddr.add(拆分[3]);
设备。添加(拆分[5])*/
System.out.println(“Mac:+Mac+”IP地址:“+splitted[0]);
System.out.println(“Mac_计数”+macCount+“Mac_地址”+Mac);
Toast.makeText(
getApplicationContext(),
“Mac_计数”+Mac计数+“Mac_地址”
+mac,Toast.LENGTH_SHORT).show();
}
/*对于(int i=0;i
试试这个