how to get client list from a router in java -


which best way entire connected clients list router in java?

i think should work so: configure properties object root/password specified, pass through login-request , @ last client list.

thanks in advance help.

you can have loop running every lan ip example: local machine ip 192.168.1.2, gonna loop 1 255 changing last number loops value , checking if reachable. example:

private collection<inetaddress> findlanmachines() throws ioexception {         string ip = "192.168.1."; //change whatever u want :- )         arraylist<inetaddress> lanmachines = new arraylist<>();         (int = 1; <= 255; i++) {             inetaddress = inetaddress.getbyname(ip+i);             if(a.isreachable(2000)) //change timeout miliseconds whatever u want, may vary depending on type of network on                                     //and capabilities of card.             lanmachines.add(a);         }         return lanmachines;     } 

this method every ip , check if reachable. cant efficient no means way can think of atm :- )

edit #1: in cases (e.x. public networks or large company buildings) devices on network claim ip more 255 ip's not enough all, other ip's may deployed 192.168.2.1 , on. can tweak code above include cases double loop. post more flexible code :- )

edit #2: here more flexible piece of code cover case proposed in edit #1, didnt know how last 2 numbers (seperated dots) called in ip called them depth , subdepth, see code comments more:

private collection<inetaddress> findlanmachines() throws ioexception {         int depth = 1; //this number range 1 x representing * in ip: 192.168.*.1         int subdepth = 255; //this range 1 x representing * in ip: 192.168.1.*         int timeout = 1000;//the ammount need wait other host reply before skip next 1 (in ms)         string ip = inetaddress.getlocalhost().tostring().split("/")[1];         string tmp = ip.substring(0,                 ip.lastindexof(".", ip.lastindexof(".") - 1))                 + ".";         arraylist<inetaddress> lanmachines = new arraylist<>();         (int j = 1; j < depth; j++) {             (int = 1; < subdepth; i++) {                 inetaddress = inetaddress.getbyname(tmp + j + "." + i);                 if (a.isreachable(timeout))                     lanmachines.add(a);             }         }         return lanmachines;     } 

this piece of code take ages find hosts work. decrease massive ammount of time needs complete, can consider making multythreaded. may not used repetedly because cause freezes , consume many resources. cheers.


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 -