I'm using getaddrinfo
to return the IP addresses for a URL input.
It's currently returning 8x IP addresses but I believe there are more.
If I call it again, it just returns the exact same addresses.
Is there a way to increase the number of IPs getaddrinfo
returns?
OS: Ubuntu
I'm not aware of any upper limit on the number of IP addresses produced by a single call to getaddrinfo
. If you are getting eight addresses, then eight addresses is how many there were in the DNS response.
If you get different IP addresses each time you call getaddrinfo
with the same hostname, then that service is doing DNS round-robin load balancing and you can call getaddrinfo
many times to attempt to enumerate all available addresses. Because DNS is cached in many places throughout the network, you will need to space out your requests: I would drop down to a lower level DNS-specific API (such as c-ares), contact the authoritative servers for the relevant DNS zone directly, and issue queries at a rate of one per minute or one per 150% of the server's declared response time-to-live, whichever is slower. Yes, this is probably going to take hours.
If you get the same IP addresses each time you call getaddrinfo
with the same hostname, but public DNS query services like nslookup.io
and digwebinterface.com
give you different addresses for that hostname, then the service is doing DNS-based geographic load balancing and there is no practical way to enumerate all of the addresses for the hostname.
Note that there are ways to host multiple servers behind a single IP address, such as reverse proxies and IP anycast; just because you have all the addresses you can find, doesn't mean you have the ability to contact all available servers.