0

I've the following problem : I'm actually making a script for an ovirt server to automatically delete virtual machine which include unregister them from the DNS. But for some very specific virtual machine there is multiple FQDN for an IP address example:

myfirstfqdn.com IN A 10.10.10.10
mysecondfqdn.com IN A 10.10.10.10

I've tried to do it with socket in Python but it return only one answer, I've also tried python with dnspython but I failed. the goal is to count the number of type A record on the dns server Anyone have an idea to do stuff like this?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Brice Harismendy
  • 113
  • 1
  • 12

2 Answers2

1

That's outright impossible. If I am in the right mood, I could add an entry to my DNS server pointing to your IP address. Generally, you cannot find it out (except for some hints in some protocols like http(s)).

glglgl
  • 89,107
  • 13
  • 149
  • 217
0

Given a zone file in the above format, you could do something like...

from collections import defaultdict

zone_file = """myfirstfqdn.com IN A 10.10.10.10
mysecondfqdn.com IN A 10.10.10.10"""

# Build mapping for lookups
ip_fqdn_mapping = defaultdict(list)

for record in zone_file.split("\n"):
    fqdn, record_class, record_type, ip_address = record.split()
    ip_fqdn_mapping[ip_address].append(fqdn)

# Lookup
ip_address_to_lookup = "10.10.10.10"
fqdns = ip_fqdn_mapping[ip_address_to_lookup]

print(fqdns)

Note: Using socket can be done like so - Python lookup hostname from IP with 1 second timeout

However this does require that DNS server that you are querying has correctly configured PTR reverse records.

https://www.cloudns.net/wiki/article/40/

Mat
  • 1,345
  • 9
  • 15