Skip to content

Instantly share code, notes, and snippets.

@patsevanton
Created February 16, 2022 06:56
Show Gist options
  • Save patsevanton/7bb376c885f3254ce66f4485606176ec to your computer and use it in GitHub Desktop.
Save patsevanton/7bb376c885f3254ce66f4485606176ec to your computer and use it in GitHub Desktop.
compare_dns
#!/usr/bin/env python
import subprocess
import six
import sys
dns_zone_domain_ru = subprocess.Popen("host -l domain.ru 10.0.0.1", shell=True, stdout=subprocess.PIPE)
list_fqdn = dns_zone_domain_ru.communicate()
for i in list_fqdn:
if isinstance(i, six.string_types):
for j in i.splitlines():
if "has address" in j:
# print(j.split()[0],j.split()[3],)
fqdn = j.split()[0]
ipaddress = j.split()[3]
# print(type(ipaddress))
query_to_test_dns_server = subprocess.Popen("dig +short " + fqdn + " @10.0.0.2", shell=True, stdout=subprocess.PIPE)
output = query_to_test_dns_server.communicate()
for k in output:
if isinstance(k, six.string_types):
for ipaddress_other_dns in k.splitlines():
if ipaddress != ipaddress_other_dns:
print(fqdn + ' have different ip address:')
print('on test-dns1: ' + ipaddress)
print('on test-dns2: ' + ipaddress_other_dns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment