作者xinsunzhong (XZ)
看板AndroidDev
标题[问题] isReachable问题
时间Mon Jun 2 19:00:35 2014
各位版大好~感谢愿意花时间近来XDD
最近有在尝试做热点管理相关的app
但是碰壁了好一阵子...
以下附上片段程式码
try {
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("..:..:..:..:..:..")) {
InetAddress address = InetAddress.getByName(splitted[0]);
boolean isReachable = address.isReachable(1000);
if(isReachable) {
mac_Count++;
macaddress.append(mac + "\n");
}
}
}
}
}
catch(Exception e){
Log.e(this.getClass().toString(), e.toString());
}
finally {
try {
br.close();
}
catch (IOException e) {
Log.e(this.getClass().toString(), e.toString());
}
}
黄色表示疑问所在
如果注解掉能够正常抓arp table资料
只是这样子不能够知道装置是不是还是连接的状态
也就是就算断连了还是会在table中
加上黄色部分是想透过isReachable来判断这个ip是不是可达
只是run出来都显示没装置连上
如果if条件改成 if(!isReachable || isReachable)
还是没跑出来 意思是布尔值是null吗??
这部分试了一个月都没有解答........
想烦请强者版友们能够提点我错在哪边或者方向吗?
感激不尽!!
--
BED ▎●▅ ▅
▎●▁▁
▎●▅▅▅
▎●▅▅
┌ ▎ ┐
▇▇▇ ▇ ▇▇▇▇ ▇▇▇▇ ●▅▅
▇▇▇▇ │ ▇▇▇▇ │
&
▎ ▎ ▎ ▎ ▎ ▎ ▎●▅▅
│ ▎ ▎│
▇▇▇▇ │ │
I magician super model basketball homeless prisoner
└ engineer
┘
player
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.118.150.45
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/AndroidDev/M.1401706842.A.E2A.html
1F:推 typepeter:搞不好是直接exception了 06/02 21:15
2F:→ typepeter:你在catch里面加个log看看 06/02 21:16
3F:→ xinsunzhong:请问再加个Log?? 06/02 22:38