Yerel ağdaki tüm bağlı aygıtları listeleyen bir işlev oluşturmaya çalışıyorum. Yaptığım şey, herhangi bir adresi x.x.x.0 - x.x.x.255 adres alanına ping etmektir, ancak düzgün çalışmıyor gibi görünmüyor. Kodumu bir şekilde açıklayabilir veya genişletebilir misiniz? Telefondan (10.0.0.17) ve varsayılan ağ geçidinden (10.0.0.138) bir yanıt alıyorum. İkincisi orada olmamalıydı (aslında varsayılan ağ geçidinin ne olduğunu bilmiyorum ama bunu görmezden geleyim). IP'yi bu bilgisayardan kaçırıyorum.Yerel ağdaki ping pili aygıtları
public ArrayList<InetAddress> getConnectedDevices(String YourPhoneIPAddress) {
ArrayList<InetAddress> ret = new ArrayList<InetAddress>();
LoopCurrentIP = 0;
// String IPAddress = "";
String[] myIPArray = YourPhoneIPAddress.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));
// 50ms Timeout for the "ping"
if (currentPingAddr.isReachable(50)) {
if(currentPingAddr.getHostAddress() != YourPhoneIPAddress){
ret.add(currentPingAddr);
}
}
} catch (UnknownHostException ex) {
} catch (IOException ex) {
}
LoopCurrentIP++;
}
return ret;
}
Btw, Emulator kullanmıyorum, telefonumu kullanıyorum! – rtc11