Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""Quad9 DNS resolutions"""
import logging

import dns.message
import httpx

from api_app.analyzers_manager import classes
Expand Down Expand Up @@ -35,21 +34,21 @@ def run(self):
# with 2 or 3 attemps the analyzer should get the data
attempt_number = 3
quad9_response = None
for attempt in range(0, attempt_number):
for attempt in range(attempt_number):
try:
quad9_response = httpx.Client(http2=True).get(
complete_url, headers=self.headers, timeout=10
)
except httpx.ConnectError as exception:
# if the last attempt fails, raise an error
if attempt == attempt_number - 1:
raise exception
else:
quad9_response.raise_for_status()

dns_response = dns.message.from_wire(quad9_response.content)
json_response = quad9_response.json()
resolutions: list[str] = []
for answer in dns_response.answer:
resolutions.extend([resolution.address for resolution in answer])
for answer in json_response.get("Answer", []):
if "data" in answer:
resolutions.append(answer["data"])

return dns_resolver_response(observable, resolutions)
5 changes: 2 additions & 3 deletions api_app/visualizers_manager/visualizers/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from api_app.analyzers_manager.observable_analyzers.dns.dns_resolvers.quad9_dns_resolver import ( # noqa: E501
Quad9DNSResolver,
)
from api_app.choices import Classification
from api_app.models import Job
from api_app.visualizers_manager.classes import VisualizableObject, Visualizer
from api_app.visualizers_manager.decorators import (
Expand Down Expand Up @@ -68,8 +67,8 @@ def _dns_resolution(self, analyzer_report: AnalyzerReport) -> VisualizableObject
value=[
self.Base(
value=(
dns_resolution["data"]
if self._job.analyzable.classification == Classification.DOMAIN
dns_resolution.get("data")
if isinstance(dns_resolution, dict) and "data" in dns_resolution
else dns_resolution
),
disable=False,
Expand Down