update dnscrypt_to_smartdns.py
This commit is contained in:
parent
a322729e2d
commit
97c16cea01
4 changed files with 308 additions and 91 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import logging
|
||||
import subprocess
|
||||
from http.client import HTTPException
|
||||
from urllib.error import URLError
|
||||
from urllib.request import urlopen, Request
|
||||
from urllib.request import urlopen
|
||||
|
||||
import dns.message
|
||||
import dns.query
|
||||
|
||||
from dnscrypt import parse, DNSoverHTTPS
|
||||
|
||||
|
|
@ -57,35 +58,30 @@ def get_not_china_doh_list():
|
|||
))
|
||||
|
||||
|
||||
# def build_dns_query(domain, record_type):
|
||||
# # require: dnspython
|
||||
# import dns.message
|
||||
# dnsq = dns.message.make_query(
|
||||
# qname=domain,
|
||||
# rdtype=record_type,
|
||||
# want_dnssec=False,
|
||||
# )
|
||||
# return dnsq
|
||||
def build_dns_query(domain, record_type):
|
||||
# require: dnspython
|
||||
dnsq = dns.message.make_query(
|
||||
qname=domain,
|
||||
rdtype=record_type,
|
||||
want_dnssec=False,
|
||||
)
|
||||
return dnsq
|
||||
|
||||
|
||||
TESTED_URL = set()
|
||||
|
||||
|
||||
def doh_tester(hostname, path):
|
||||
# www.google.com A
|
||||
dnsq = b'\xf9\x04\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x06google\x03com\x00\x00\x01\x00\x01'
|
||||
dnsq = build_dns_query("www.google.com", "A")
|
||||
url = 'https://' + hostname + path
|
||||
if url in TESTED_URL:
|
||||
return False
|
||||
request = Request(url, data=dnsq)
|
||||
request.add_header('accept', 'application/dns-message')
|
||||
request.add_header('content-type', 'application/dns-message')
|
||||
try:
|
||||
with urlopen(request, timeout=3) as response:
|
||||
response.read()
|
||||
print('{url}\tok'.format(url=url))
|
||||
TESTED_URL.add(url)
|
||||
return True
|
||||
except (URLError, TimeoutError, ConnectionError, HTTPException) as e:
|
||||
dns.query.https(dnsq, where=url, timeout=3)
|
||||
print('{url}\tok'.format(url=url))
|
||||
TESTED_URL.add(url)
|
||||
return True
|
||||
except BaseException as e:
|
||||
print('{url}\tfailed\t{error}'.format(url=url, error=e))
|
||||
TESTED_URL.add(url)
|
||||
return False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue