android arp -a命令,java - Android arp table - developing questions - Stack Overflow

I've got two problems with the android app I'm writing.

I'm reading out the local arp table from /proc/net/arp and save ip and corresponding mac address in a hash map. See my function. It's working properly.

/**

* Extract and save ip and corresponding MAC address from arp table in HashMap

*/

public Map 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);

}

First problem:

I'm also using a broadcast receiver. When my app receives the State WifiManager.NETWORK_STATE_CHANGED_ACTION i check if the connection to the gateway is established. If true i call my function to read the arp table. But in this stage the system has not yet builded up the arp table. Sometimes when i receive the connection state the arp table is sill empty.

Anyone got an idea to solve this?

Second problem:

I want to save the ip and mac address of the gateway in a persistent way. Right now i'm using Shared Preferences for this. Maybe it's better to write to an internal storage?

Any tips?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值