ver todas tipos redes para lista las comandos all android networking local ping

android - todas - Listar dispositivos en la red local con ping



tipos de comandos de red (1)

Aquí hay un bucle ligeramente modificado que debería hacer el truco (o funcionó para mí al menos);

try { NetworkInterface iFace = NetworkInterface .getByInetAddress(InetAddress.getByName(YourIPAddress)); for (int i = 0; i <= 255; i++) { // build the next IP address String addr = YourIPAddress; addr = addr.substring(0, addr.lastIndexOf(''.'') + 1) + i; InetAddress pingAddr = InetAddress.getByName(addr); // 50ms Timeout for the "ping" if (pingAddr.isReachable(iFace, 200, 50)) { Log.d("PING", pingAddr.getHostAddress()); } } } catch (UnknownHostException ex) { } catch (IOException ex) { }

Intento crear una función que liste todos los dispositivos conectados en una red local. Lo que hago es hacer ping a cualquier dirección del espacio de direcciones xxx0 a xxx255, pero parece que no funciona correctamente. ¿Alguien podría explicar o extender mi código de alguna manera? Recibo una respuesta del teléfono (10.0.0.17) y una puerta de enlace predeterminada (10.0.0.138). Este último ni siquiera debería estar allí (de hecho, no sé lo que es una puerta de enlace predeterminada, pero ignorar eso). Sin embargo, me falta el IP de esta computadora.

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; }