mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 21:08:03 +00:00
DNS: ignore DNS resolvers which don't give us JSON
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import requests
|
import requests
|
||||||
from ipaddress import ip_address
|
from ipaddress import ip_address
|
||||||
|
from json.decoder import JSONDecodeError
|
||||||
|
|
||||||
resolvers = [
|
resolvers = [
|
||||||
"https://dns.nextdns.io/dns-query",
|
"https://dns.nextdns.io/dns-query",
|
||||||
@@ -31,7 +32,11 @@ class DNS:
|
|||||||
headers={"accept": "application/dns-json"},
|
headers={"accept": "application/dns-json"},
|
||||||
)
|
)
|
||||||
|
|
||||||
j = r.json()
|
try:
|
||||||
|
j = r.json()
|
||||||
|
except JSONDecodeError:
|
||||||
|
# ignore DNS resolvers which don't give us JSON
|
||||||
|
continue
|
||||||
if "Answer" in j:
|
if "Answer" in j:
|
||||||
for answer in j["Answer"]:
|
for answer in j["Answer"]:
|
||||||
if answer["type"] == dns_types[typ]:
|
if answer["type"] == dns_types[typ]:
|
||||||
@@ -47,7 +52,11 @@ class DNS:
|
|||||||
headers={"accept": "application/dns-json"},
|
headers={"accept": "application/dns-json"},
|
||||||
)
|
)
|
||||||
|
|
||||||
j = r.json()
|
try:
|
||||||
|
j = r.json()
|
||||||
|
except JSONDecodeError:
|
||||||
|
# ignore DNS resolvers which don't give us JSON
|
||||||
|
continue
|
||||||
if "Answer" in j:
|
if "Answer" in j:
|
||||||
result = (0, None)
|
result = (0, None)
|
||||||
for answer in j["Answer"]:
|
for answer in j["Answer"]:
|
||||||
|
|||||||
Reference in New Issue
Block a user