How to clear ARP table through code?

I have an android tab with hotspot enabled. When other Wi-Fi enabled devices connect to my Android device, their IP address and other data is stored in the ARP table, and I can access these details by reading from "/ proc / net / arp" and I show them in the list. But when one device disconnects from my hotspot-enabled Android tab, the corresponding data associated with this device is not cleared from the ARP table (When I read "/ proc / net / arp", the ARP table still contains information about disconnecting the device) . I want to clear information about a device that is disconnected.

Here is the code (access to the ARP table)

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; } 

Hope I understood my question.

+4
source share

Source: https://habr.com/ru/post/1442275/


All Articles