小编Ice*_*rth的帖子

Android arp表——开发题

我正在编写的 android 应用程序有两个问题。

我正在读取本地 arp 表/proc/net/arp,并将 ip 和相应的 mac 地址保存在哈希映射中。看我的功能。它工作正常。

    /**
     * Extract and save ip and corresponding MAC address from arp table in HashMap
     */
    public Map<String, String> createArpMap() throws IOException {      
        checkMapARP.clear();
        BufferedReader localBufferdReader = new BufferedReader(new FileReader(new File("/proc/net/arp")));
        String line = "";       

        while ((line = localBufferdReader.readLine()) != null) {            
            String[] ipmac = line.split("[ ]+");
            if (!ipmac[0].matches("IP")) {
                String ip = ipmac[0];
                String mac = ipmac[3];
                if (!checkMapARP.containsKey(ip)) {
                    checkMapARP.put(ip, mac);               
                }                   
            }
        }
        return Collections.unmodifiableMap(checkMapARP); …
Run Code Online (Sandbox Code Playgroud)

java android

5
推荐指数
1
解决办法
7199
查看次数

标签 统计

android ×1

java ×1