-
Notifications
You must be signed in to change notification settings - Fork 6
/
getsoa.py
25 lines (21 loc) · 832 Bytes
/
getsoa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'''
Module used to fetch SOA (domain and IP) records for the given target domain
'''
import utils
from scapy.all import IP, UDP, DNS, DNSQR, sr1
from argparse import Namespace
def expandLayers(x, payload):
yield getattr(x, payload)
while x.payload:
x = x.payload
yield getattr(x, payload)
def getSoaForDomain(args):
pkt = IP(dst="8.8.8.8") / UDP(sport=utils.getRandomPort()) / DNS(qr=0, rd=1, qd=DNSQR(qname=args.targetDomain, qtype="NS"))
ans = sr1(pkt, verbose=False)
args.soaDomain = list(expandLayers(ans[DNS].an, "rdata"))
args.soaIP = list()
for domain in args.soaDomain:
pkt = IP(dst="8.8.8.8") / UDP(sport=utils.getRandomPort()) / DNS(qd=DNSQR(qname=domain, qtype="A"))
ans = sr1(pkt, verbose=False)
args.soaIP.append(ans[DNS].an.rdata)
print args