Identification of application on the network

1
Hello, I'm creating a barcode reading system where I have an application on a device that serves as a camera, and sends that information to a web page on a PC. But I did create that page did a search on the local network of the user and found the IP of the device where the application would be. Is it possible to do with JavaScript or PHP? If so, please tell me the name of the technology used to search for it!

    
asked by anonymous 09.08.2018 / 18:17

1 answer

0

With android (java), you can do this:

public static String getLocalIpAddress() {
    try {
        // gera uma lista enumerada de todas as interfaces de endereços de rede
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement(); // pega o elemento
            // gera uma nova lista com todos os endereços de IP da interface
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement(); // pega o endereço IP
                // verifica se este endereço não é um "localhost" e verifica se este é um IP de protocolo  IPv4 
                if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                    // retorna o valor em string
                    return inetAddress.getHostAddress();
                }
            }
        }
    } catch (SocketException ex) {
        ex.printStackTrace();
    }
    return null;
}

This function returns IPv4 protocol IP

If you want IPv6, you should use in your if of this form:

if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet6Address)

Or so to get either:

if (!inetAddress.isLoopbackAddress() && (inetAddress instanceof Inet6Address || inetAddress instanceof Inet4Address))

And then you send this information to the site. Best, right?

Sources:

Android documentation

StackOverflow

09.08.2018 / 21:34