Java – Find machines on the local network based on port (network discovery) in android

Find machines on the local network based on port (network discovery) in android… here is a solution to the problem.

Find machines on the local network based on port (network discovery) in android

I want my android app to scan every PC on the local network 192.168.1.1-254 for machines that have a given port open. I know there are several manual ways to do this, but it would be a lot of code and would take some time every time you needed to search. Is there a way to quickly specify a port and search for a local device with the port open?

Example. The desktop has a web server on port 8888, you know the port but not the IP, give the port to the application and let it quickly display the IP.

Solution

I assume you know how to connect to a TCP server.
If not, pass first

http://examples.javacodegeeks.com/android/core/socket-core/android-socket-example/

You can try opening multiple threads, each waiting to connect to a specific IP/port (and some timeout value). If the thread produces an exception, it means that the connection was unsuccessful. Otherwise, add the IP address to your Open_Devices list.

Related Problems and Solutions