Reputation: 655
I need to build a Python list of addresses contained in a RDNS request. The scapy answer looks like this:
<DNSRR rrname='www.google.ca.' type=A rclass=IN ttl=118 rdata='184.150.153.232' |<DNSRR rrname='www.google.ca.' type=A rclass=IN ttl=118 rdata='184.150.153.226' | ...
How can I extract all rdata fields and put them in a Python list? (In the above response there where 16 of them).
Upvotes: 1
Views: 120
Reputation: 3356
Scapy's DNS layers are a bit tricky when it comes to resource records as the deserialized resource records do not seem to interface like packetlistfields.
This should give you an idea on how to access those fields:
>>> answer = sr1(IP(dst="8.8.8.8")/UDP(dport=53)/DNS(rd=1,qd=DNSQR(qname="www.google.com")),verbose=0)
>>> rdatalst = []
>>> for rr in xrange(p[DNS].ancount):
... rdatalst.append(p[DNS].an[x].rdata)
>>> print rdatalst
['212.247.8.59', '212.247.8.59', '212.247.8.59', '212.247.8.59', '212.247.8.59', '212.247.8.59', '212.247.8.59', '212.247.8.59', '212.247.8.59', '212.247.8.59', '212.247.8.59', '212.247.8.59']
Upvotes: 2