MCPcopy Create free account
hub / github.com/adobe/Marinus / lookup_hostname

Function lookup_hostname

python3_cron_scripts/sonar_round_two.py:60–98  ·  view source on GitHub ↗

Use Google DNS over HTTPS to lookup host

(logger, host, zones, round_three)

Source from the content-addressed store, hash-verified

58
59
60def lookup_hostname(logger, host, zones, round_three):
61 """
62 Use Google DNS over HTTPS to lookup host
63 """
64 try:
65 req = requests.get("https://dns.google.com/resolve?name=" + host)
66 except:
67 logger.error("Requests attempt failed!")
68 return []
69
70 if req.status_code != 200:
71 logger.error("Error looking up: " + host)
72 return []
73
74 nslookup_results = json.loads(req.text)
75
76 if nslookup_results["Status"] != 0:
77 logger.warning("Status error looking up: " + host)
78 return []
79
80 if "Answer" not in nslookup_results:
81 logger.warning("Could not find Answer in DNS result for " + host)
82 logger.warning(req.text)
83 return []
84
85 results = []
86 for answer in nslookup_results["Answer"]:
87 if answer["type"] == 5:
88 results.append({"type": "cname", "value": answer["data"][:-1]})
89 if is_tracked_zone(answer["data"][:-1], zones):
90 add_to_list(answer["data"][:-1], round_three)
91 elif answer["type"] == 1:
92 results.append({"type": "a", "value": answer["data"]})
93 elif answer["type"] == 28:
94 results.append({"type": "aaaa", "value": answer["data"]})
95 else:
96 logger.warning("Unrecognized type: " + str(answer["type"]))
97
98 return results
99
100
101def main(logger=None):

Callers

nothing calls this directly

Calls 2

is_tracked_zoneFunction · 0.70
add_to_listFunction · 0.70

Tested by

no test coverage detected