DNSPython: NoAnswer in MX and NS

1

I am reading the book "Python for Pentesters" by Daniel Echeverri Montoya. Being on page 17 I tried to test the code, however when trying to execute the function dns.resolver.query with the parameter MX and NS I get an error of NoAnswer .

Here I leave the code:

import dns
import dns.resolver

pagina_web = "www.google.com"

ansMX = dns.resolver.query(pagina_web, 'MX')
ansNS = dns.resolver.query(pagina_web, 'NS')

print("\nImprimiendo ansMX:")
print("--------------------------------")
print(ansMX.response.to_text())

print("\nImprimiendo ansNS:")
print("--------------------------------")
print(ansNS.response.to_text())

The two errors are the following:

  • MX:

    Traceback (most recent call last):
      File "C:/Users/zorro/Desktop/Programas/Python/Pentester/Ejemplo 1/Ejemplo1.py", line 10, in <module>
        ansMX = dns.resolver.query(pagina_web, 'MX')
      File "C:\Users\zorro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\dnspython-1.15.0-py3.6.egg\dns\resolver.py", line 1132, in query
      File "C:\Users\zorro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\dnspython-1.15.0-py3.6.egg\dns\resolver.py", line 1053, in query
      File "C:\Users\zorro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\dnspython-1.15.0-py3.6.egg\dns\resolver.py", line 234, in __init__
    dns.resolver.NoAnswer: The DNS response does not contain an answer to the question: www.google.com. IN MX
    
  • NS:

    Traceback (most recent call last):
      File "C:/Users/zorro/Desktop/Programas/Python/Pentester/Ejemplo 1/Ejemplo1.py", line 11, in <module>
        ansNS = dns.resolver.query(pagina_web, 'NS')
      File "C:\Users\zorro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\dnspython-1.15.0-py3.6.egg\dns\resolver.py", line 1132, in query
      File "C:\Users\zorro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\dnspython-1.15.0-py3.6.egg\dns\resolver.py", line 1053, in query
      File "C:\Users\zorro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\dnspython-1.15.0-py3.6.egg\dns\resolver.py", line 234, in __init__
    dns.resolver.NoAnswer: The DNS response does not contain an answer to the question: www.google.com. IN NS
    

Versions of the programs that intervene in the code:

  • Windows 10 Pro
  • Python 3.6
  • DNSPython
  • PyCharm Community 2017.2.4
asked by Alvaro Garcia 15.03.2018 в 10:50
source

2 answers

2

For clarifying the comment that has solved the problem:

ansMX = dns.resolver.query(pagina_web, 'MX')
ansNS = dns.resolver.query(pagina_web, 'NS')

You are requesting MX and NS records, that is, you are requesting the records associated with the address given for Mail eXchange and Name Server .

The domain google.com has many subdomains:

  • www for the search engine
  • mail for gmail
  • aspmx.l for mail exchange (MX)
  • maps
  • play
  • ns1, ns2, ns3, ns4 ... for DNS (NS)

But when you narrow the search to www.google.com you will not get information about the addresses used for mail or DNS delegation.

Therefore, you have to go to the most global, google.com

    
answered by 15.03.2018 / 13:59
source
1

Answered in the comment of @FJSevilla:

  

Use the non-www version:

pagina_web = "google.com"

The response I got ( dns.resolver.NoAnswer ) was not an error in the code, but was the correct answer: www.google.com has no NS or MX records.

On the other hand, google.com does have NS and MX records, and so I could get the answer.

    
answered by 15.03.2018 в 11:43