android - Get the list of all the device connected in same network -
how can list of device connected in same wifi network. did find couple of applications working available on google play "who on wifi" , "wifi inspector". want implement same functionality in application.
i find out code show connected ips same wi-fi:
private int loopcurrentip = 0; string ad ; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); //arraylist<inetaddress> ar = getconnecteddevices( ); } public arraylist<inetaddress> getconnecteddevices(string yourphoneipaddress) { arraylist<inetaddress> ret = new arraylist<inetaddress>(); loopcurrentip = 0; string ipaddress = ""; string[] myiparray = yourphoneipaddress.split("\\."); inetaddress currentpingaddr; (int = 0; <= 255; i++) { try { // build next ip address currentpingaddr = inetaddress.getbyname(myiparray[0] + "." + myiparray[1] + "." + myiparray[2] + "." + integer.tostring(loopcurrentip)); ad = currentpingaddr.tostring(); ///////////////// log.d("myapp",ad); ////////////// // 50ms timeout "ping" if (currentpingaddr.isreachable(50)) { ret.add(currentpingaddr); ad = currentpingaddr.tostring(); ///////////////// log.d("myapp",ad); ////////////// } } catch (unknownhostexception ex) { } catch (ioexception ex) { } loopcurrentip++; } return ret; }
Comments
Post a Comment