作为项目的一部分,我正在构建一个映射家庭网络的应用程序,我找到了以下代码,但我找不到所有连接到网络的设备(IP 地址)的帮助。
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;
}