我如何找到使用Android连接到家庭网络的所有设备?
作为一个项目的一部分,我正在构建一个映射家庭网络的应用程序,我发现了以下代码,但我无法找到所有连接到网络的设备(IP地址)的帮助我如何找到使用Android连接到家庭网络的所有设备?,android,Android,作为一个项目的一部分,我正在构建一个映射家庭网络的应用程序,我发现了以下代码,但我无法找到所有连接到网络的设备(IP地址)的帮助 protectedstring doInBackground(String…aurl){ LoopCurrentIP=0; 字符串IPAddress=“”; 字符串[]myIPArray=aurl[0]。拆分(“\\”; InetAddress currentPingAddr; 对于(int i=0;i)是否出现任何错误?换句话说,当您运行该代码时会发生什么?API应
protectedstring doInBackground(String…aurl){
LoopCurrentIP=0;
字符串IPAddress=“”;
字符串[]myIPArray=aurl[0]。拆分(“\\”;
InetAddress currentPingAddr;
对于(int i=0;i)是否出现任何错误?换句话说,当您运行该代码时会发生什么?API应该可以帮助您完成此操作。没有,但我找不到ipaddress@uʍopǝpısdn返回空列表
protected String doInBackground(String... aurl) {
LoopCurrentIP = 0;
String IPAddress = "";
String[] myIPArray = aurl[0].split("\\.");
InetAddress currentPingAddr;
for (int i = 0; i <= 255; i++) {
try {
// build the next IP address
currentPingAddr = InetAddress.getByName(myIPArray[0] + "." +
myIPArray[1] + "." +
myIPArray[2] + "." +
Integer.toString(LoopCurrentIP));
IPAddress = currentPingAddr.toString();
publishProgress(""+(int)((i*100)/255));
Log.d("MyApp",IPAddress);
// 50ms Timeout for the "ping"
if (currentPingAddr.isReachable(1000)) {
textView.setText(currentPingAddr.toString());
ret.add(currentPingAddr);
Log.d("MyApp",IPAddress);
}
} catch (UnknownHostException ex) {
} catch (IOException ex) {
}
LoopCurrentIP++;
}
return null;
}