Dnspython is a Python-implemented DNS toolkit that supports almost all record types, can be used for querying, transmitting, and dynamically updating zone information, while supporting Tsig (transactional signature) authentication messages and EDNS0 (extended DNS). Can replace tools such as Nslookup,dig.
#pip安装pip3 Install dnspython# Latest version v1.15.0
Module Domain Name resolution method detailed
Dnspython provides a number of DNS processing methods, the most commonly used is the domain name query.
Dnspython provides a DNS parser class------resolver, which uses its query method to implement the querying function of the domain name.
Query (self,qname,rdtype=1,rdclass=1,tcp=false,source=none,raise_on_no_answer=true,source_port=0)
QName the domain name for the query
Rdtype used to specify the type of RR resource
A record, converting the hostname to an IP address
MX record, mail exchange record, define mail server domain name
CNAME records, alias Records, implementing mappings between domain names
NS records, domain name servers for labeled zones, and authorization subdomains
PTR records, reverse resolution, and a record instead, convert IP to host name
SOA record, definition of a starting authorization area
Rdclass is used to specify the network type, such as in,ch,hs,in as the default
TCP Specifies whether the query enables the TCP protocol, default false (not enabled)
Source,source_port Specify the query source address and Port
Raise_on_no_answer query Whether no answer triggers an exception
Common parsing Type Sample script
A record
#!/usr/bin/env python#-*-coding:utf-8-*-#Author: ccoo2import dns.resolver# domain = input ("Please enter the domain name address:") domain = ' Www.bai Du.com ' A = dns.resolver.query (domain, ' a ') for I in A.response.answer: # Print (i) for J in I.items: print (j)
MX record
Python---Dnspython