java - Speed up finding devices connected to a Wifi network and get device name -


i'm writing java program show names , ip addresses of devices connected wifi network.

i've figured out ip address part. here's code :

public static void main(string[] args) throws ioexception {     inetaddress localhost = inetaddress.getlocalhost();     // code assumes ipv4 used        byte[] ip = localhost.getaddress();     (int = 1; <= 254; i++) {         ip[3] = (byte) i;         inetaddress address = inetaddress.getbyaddress(ip);         if (address.isreachable(1000)) {             // machine turned on , can pinged             system.out.println(address + "is online");         } else if (!address.gethostaddress().equals(address.gethostname())) {             // machine known in dns lookup             system.out.println(address + "is in dns lookup");         } else {             // host address , host name equal, meaning host name not resolved             system.out.println(address + " not online");         }     } } 

this code works , shows ip addresses of connected devices.
there 2 problems i'm facing:

  1. i'm not able connected device's name. can ip address.
  2. this program works slow. takes 254 seconds complete.

so how display name of connected devices , there way speed program up?

any appreciated!

this program works slow. takes 254 seconds complete.

i think know why. inetaddress documentation:

public boolean isreachable(int timeout)                 throws ioexception 

the timeout value, in milliseconds, indicates maximum amount of time try should take. if operation times out before getting answer, host deemed unreachable. negative value result in illegalargumentexception being thrown.

therein lies problem. if allocate second timeout value, program take 254 seconds complete if hosts unreachable. try reducing it.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -