1

I use dnspython to query a DNS server to resolve a domain name to its IP(s).

When I try to resolve "google.co.uk" I get only one IP. However, using another resolver tool I get another IP. Both IPs are correct and I tested them by placing the IPs in the browser, both open "google.co.uk".

Clearly there are more than IP asssigned for the domain name I am testing. Is there any way I can use in dnspython to retrieve all IPs for a given domain name?

Here is my simple script:

import dns.resolver

def resolve(domain):
  resolveList = []
      resolver = dns.resolver.Resolver(); #create a new instance named Resolver
      answer = resolver.query(domain,"A");
      y=0
      for rData in answer: 
          resolveList.append(rData)
          ++y        
  return resolveList

domainName = "google.co.uk"
queryResult = resolve(domainName);
for result in queryResult:
    print queryResult[0]
None
  • 281
  • 1
  • 6
  • 16

1 Answers1

5

In the general case, no, there is no way to know when you have exhaustively enumerated all IP addresses in active use for a particular host name. Google is a good example; depending on your location in the world and their current load, they will return some, but not all, of their addresses, for load-balancing and similar purposes.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Couldn't agree more. This [SO answer](https://stackoverflow.com/questions/35892868/get-all-ips-associated-with-a-url-python) also explains the same. – amanb Apr 01 '18 at 13:05
  • Agree with the above. They use geoip load balancing to serve you with the closest server. Coupled with anycast dns too. This can be useful not for your python script but for ips queries across the globe: https://www.whatsmydns.net – mr4kino Apr 02 '18 at 17:46