DNSpython on debian installation

To use dns lookups in python scripts on your raspberry or any other debian / ubuntu based system, dnspython is the perfect point to start.

Howto:

sudo apt-get install python-pip
pip install dnspython

Then try the examples on : http://www.dnspython.org/examples.html

Example Python script:

#!/usr/local/bin/python
import dns.resolver
domain = dns.name.from_text(dns_to_look)
nameserver = '8.8.8.8' #this is google nameserver, use your fav. DNS server
query = dns.message.make_query("google.com", dns.rdatatype.ANY)
response = dns.query.udp(query, nameserver, timeout = 2)
print response

Will result in:

python dns_test.py
id 41318
opcode QUERY
rcode NOERROR
flags QR RD RA
;QUESTION
google.com. IN ANY
;ANSWER
google.com. 182 IN A 173.194.113.169
google.com. 182 IN A 173.194.113.165
google.com. 182 IN A 173.194.113.166
google.com. 182 IN A 173.194.113.174
google.com. 182 IN A 173.194.113.160
google.com. 182 IN A 173.194.113.162
google.com. 182 IN A 173.194.113.168
google.com. 182 IN A 173.194.113.163
google.com. 182 IN A 173.194.113.161
google.com. 182 IN A 173.194.113.167
google.com. 182 IN A 173.194.113.164
google.com. 13460 IN NS ns1.google.com.
google.com. 13460 IN NS ns3.google.com.
google.com. 13460 IN NS ns4.google.com.
google.com. 13460 IN NS ns2.google.com.
google.com. 100 IN AAAA 2a00:1450:4005:808::1007
google.com. 50 IN SOA ns1.google.com. dns-admin.google.com. 1549778 7200 1800 1209600 300
;AUTHORITY
;ADDITIONAL

You can now use the script in your own scripts to search for DNS results.

To find some examples for ussage of DNS python see the example page of the project: http://www.dnspython.org/examples.html.
I am using the script to check the DNS settings for domains found with other tools that I am running. You could also store the DNS entries for your requests and build your database, that would result in a „low cost passive DNS database“.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.