如何通过代码清除ARP表?

时间:2012-10-26 09:09:25

标签: android linux android-wifi

我有一个安装了热点的android标签页。当其他支持wifi的设备连接到我的Android设备时,他们的IP地址和其他详细信息将存储在ARP表中,我可以通过读取“/ proc / net / arp”来访问这些详细信息,并在列表中显示它们。但是当一个设备从我的热点启用的android选项卡断开连接时,那个与该设备相关的相应详细信息没有从ARP表中清除(当我读取“/ proc / net / arp”时,ARP表仍然保存断开连接的详细信息设备)。我想清除断开连接的设备的详细信息。

这是代码(访问ARP表)

public ArrayList<ClientScanResultSO> getClientList(boolean onlyReachables,
    int reachableTimeout) {
    BufferedReader br = null;
    ArrayList<ClientScanResultSO> result = null;

    try {
        result = new ArrayList<ClientScanResultSO>();
        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("..:..:..:..:..:..")) {
                    boolean isReachable = InetAddress
                            .getByName(splitted[0]).isReachable(
                                    reachableTimeout);
                    String name = InetAddress.getByName(splitted[0]).getHostName();
                    if (!onlyReachables || isReachable) {
                        result.add(new ClientScanResultSO(splitted[0],
                                splitted[3], splitted[5], isReachable,name));
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.e(this.getClass().toString(), e.getMessage());
    } finally {
        try {
            br.close();
        } catch (IOException e) {
            Log.e(this.getClass().toString(), e.getMessage());
        }
    }

    return result;
}

希望我对我的问题很清楚。

0 个答案:

没有答案