networking - How to get a list of IP connected in same network (subnet) using Java -
how list of ip addresses devices connected same subnet using java?
this should work when hosts on network react icmp packages (ping) (>jdk 5):
public void checkhosts(string subnet){ int timeout=1000; (int i=1;i<255;i++){ string host=subnet + "." + i; if (inetaddress.getbyname(host).isreachable(timeout)){ system.out.println(host + " reachable"); } } }
invoke method subnet (192.168.0.1-254) this:
checkhosts("192.168.0");
didnt test should work kinda this. checks 254 hosts in last byte of ip address...
check:
http://download-llnw.oracle.com/javase/6/docs/api/java/net/inetaddress.html#isreachable%28int%29 http://blog.taragana.com/index.php/archive/how-to-do-icmp-ping-in-java-jdk-15-and-above/
hope helped
Comments
Post a Comment