Skip to content

Instantly share code, notes, and snippets.

@vdchuyen
Last active September 25, 2023 15:29
Show Gist options
  • Save vdchuyen/2d14ac7de569ed2a309b2514f708542e to your computer and use it in GitHub Desktop.
Save vdchuyen/2d14ac7de569ed2a309b2514f708542e to your computer and use it in GitHub Desktop.
Python script to lookup NS PTR with list prefixes from one AS
##
# chuyenvd@vng
# 2023-09-25
##
import dns.resolver
import ipaddress
AS = "AS12345"
with open(AS) as f:
for prefix in f.readlines():
prefix = prefix.split('\t')
for i in prefix:
ip = ipaddress.IPv4Interface(i)
try:
ptr_zone = ipaddress.ip_address(ip.ip).reverse_pointer
lk_zone = ptr_zone.replace('0.', '', 1)
ns = dns.resolver.resolve(lk_zone, 'NS')
for i in ns.response.answer:
print('\x1b[6;30;42m' + 'NS found:',lk_zone + '\x1b[0m')
for j in i.items:
print('NS:',j.to_text())
except:
print('\033[91m' + 'NS missing:',lk_zone + '\033[0m')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment