判断dns支持不支持edns
-
pip install clientsubnetoption
(works for both Python2 & Python3) -
Import
clientsubnetoption
and dependancies you\’ll need:import dns import clientsubnetoption
-
Setup your
ClientSubnetOption
with the information you want:cso = clientsubnetoption.ClientSubnetOption(\'1.2.3.4\')
-
Create your DNS packet:
message = dns.message.make_query(\'google.com\', \'A\')
-
Add the edns option:
message.use_edns(options=[cso])
-
Use
message
to make your query:r = dns.query.udp(message, \'8.8.8.8\')
-
Option information is now at
r.options
and there can be multiple, so you may need to iterate through them to find theClientSubnetOption
object.for options in r.options: if isinstance(options, ClientSubnetOption): # do stuff here pass
-
ip_list = [] cname_probe = "dl.3366.com" # ip = "27.40.1.34" # ip = "218.61.196.242" ip = "218.61.196.242" cso = clientsubnetoption.ClientSubnetOption(ip, 32) msg = dns.message.make_query(cname_probe, \'A\') msg.use_edns(edns=True, ednsflags=0, options=[cso]) msg.use_edns(options=[cso]) # dns_serv = "218.61.196.242" # dns_serv = "119.6.103.36" dns_serv = "119.29.29.29" res = dns.query.udp(msg, dns_serv) print res.options for options in res.options: if isinstance(options, clientsubnetoption.ClientSubnetOption): # do stuff here print "yes" else: print "not type" if not res.answer: print res.answer raise Exception("edns no answer") rrset_a = res.answer[-1] for rdata in rrset_a: ip_list.append(str(rdata.to_text())) return ip_list