title: How do we do DNS query in Python
body: <p>How do we do a DNS query, expecially MX query, in Python by not installing any third party libs.</p>
  
  <p>I want to query the MX record about a domain, however, it seems that <code>socket.getaddrinfo</code> can only query the A record.</p>
  
  <p>I have tried this:</p>
  
  <pre><code>python -c "import socket; print socket.getaddrinfo('baidu.com', 25, socket.AF_INET, socket.SOCK_DGRAM)"
  </code></pre>
  
  <p>This prints </p>
  
  <pre><code>[(2, 2, 17, '', ('220.181.57.217', 25)), (2, 2, 17, '', ('123.125.114.144', 25)), (2, 2, 17, '', ('180.149.132.47', 25))]
  </code></pre>
  
  <p>However, we can not telnet it with <code>telnet 220.181.57.217 25</code> or <code>telnet 123.125.114.144 25</code> or <code>telnet 180.149.132.47 25</code>.</p>