Search code examples
javaperformancednsiplan

InetAddress.getByName(FQDN) vs InetAddress.getByName(IP), performance issues


I have troubles figuring out why resolving an IP takes so much longer then resolving the domain name. I do understand that the IP has to be converted in order to be used by the getByName method. But this:

InetAddress address = InetAddress.getByName("google.com");
System.out.println("Reachable: " + address.isReachable(10000));

runs almost 20 times faster then this:

InetAddress address = InetAddress.getByName("192.168.1.1");
System.out.println("Reachable: " + address.isReachable(10000));

My goal is to search a specific network segment for live hosts by IP-Adress. So going through this 65025 times to run from 192.168.1.1 till 192.168.255.255 doesn't seem to be to smart. :-(

Is there a better way of doing this. Unfortunately calling the "ping-command" is not an option.

Cheers,

Stephanie


Solution

  • Thanks Calle, it also seems that playing around with portscans and many DNS lookups can trigger funny effects on the network infrastructure. After running a couple of those lookups inside a for loop with multiple treads I got a call asking what I was doing. :-(

    Cheers,

    Stephanie