0

I'm not very good at programming but what I'd like to do is have a Python script that would do certain actions depending on whether a domain has its nameservers pointed to X or whether it has a CNAME record pointed to X specific IP.

So basically: if domain has CNAME pointed to X do Y if domain has nameservers pointed to X1 and X2 do Z.

Does anyone know how that could be done?

EDIT: I've tried the following (with proper tabs of course) only the result is always 'No' even though the CNAME does point to what I've set. I'm probably misunderstanding something somewhere.

domain = 'example.com' 
answers = dns.resolver.resolve(domain,'CNAME') 
for server in answers:         
print(server.target)         
if server.target == 'xdomain.org': 
print("Yes")         
else:                 
print("No")
Reception123
  • 73
  • 1
  • 9
  • 1
    This is trivial once you figure out how to retrieve the DNS record for the domain and get the information for `CNAME` and nameservers. Did you try [looking for that?](https://www.google.com/search?q=python+get+dns+record+for+domain) – Pranav Hosangadi Dec 14 '22 at 18:26
  • Possible duplicates: [How can I find the authoritative DNS server for a domain using dnspython?](/q/4066614/4518341) and [How can I get DNS records for a domain in python?](/q/1162230/4518341) (These are the top hits I found on Google that look promising, but I haven't tried them myself.) – wjandrea Dec 14 '22 at 18:37
  • Thank you for the replies. I have tried but (as I say I do not have much experience) when doing if target = 'ns.domain.org' for example and I ask it to print yes if it is pointing (which the domain is) it says no. – Reception123 Dec 14 '22 at 18:44
  • `domain = 'example.com' answers = dns.resolver.resolve(domain,'CNAME') for server in answers: print(server.target) if server.target == 'xdomain.org': print("Yes") else: print("No")` (It prints no even though the result matches the domain I indicate in the ==) – Reception123 Dec 14 '22 at 18:46
  • @Reception123 Please [edit] the question to add details. Comments don't support fancy formatting. – wjandrea Dec 14 '22 at 19:01

0 Answers0