quick_fix_to_subdomain_scrapper

#10
tdagent/tools/get_domain_information.py CHANGED
@@ -77,11 +77,12 @@ def get_geolocation(ip: str) -> dict[str, Any] | str:
77
  except Exception as e: # noqa: BLE001
78
  return str(e)
79
 
 
80
  def _request_dns_record( # noqa: D417
81
  domain: str,
82
  record_type: str,
83
  timeout: float = 0.5,
84
- ) -> list[str]:
85
  """Utility to build dns resolve requests that do not use port 53.
86
 
87
  Args:
@@ -180,6 +181,7 @@ def enumerate_dns(domain_name: str) -> dict[str, Any] | None:
180
  enumeration[record_type] = [str(e)]
181
  return enumeration if enumeration else None
182
 
 
183
  def resolve_subdomain_ipv4(domain: str) -> str | None:
184
  """Resolve the IPv4 address of a domain.
185
 
@@ -192,11 +194,15 @@ def resolve_subdomain_ipv4(domain: str) -> str | None:
192
  is returned.
193
  """
194
  try:
195
- _request_dns_record(domain, "A", timeout=0.6)
196
- return domain # noqa: TRY300
 
 
 
197
  except Exception: # noqa: BLE001
198
  return None
199
 
 
200
  @cachetools.cached(
201
  cache=cachetools.TTLCache(maxsize=_CACHE_MAX_SIZE, ttl=_CACHE_TTL_SECONDS),
202
  )
 
77
  except Exception as e: # noqa: BLE001
78
  return str(e)
79
 
80
+
81
  def _request_dns_record( # noqa: D417
82
  domain: str,
83
  record_type: str,
84
  timeout: float = 0.5,
85
+ ) -> list[str]:
86
  """Utility to build dns resolve requests that do not use port 53.
87
 
88
  Args:
 
181
  enumeration[record_type] = [str(e)]
182
  return enumeration if enumeration else None
183
 
184
+
185
  def resolve_subdomain_ipv4(domain: str) -> str | None:
186
  """Resolve the IPv4 address of a domain.
187
 
 
194
  is returned.
195
  """
196
  try:
197
+ ipv4 = _request_dns_record(domain, "A", timeout=0.6)
198
+ if ipv4:
199
+ return domain
200
+ msg = "Cannot resolve it: it is likely non-existing"
201
+ raise Exception(msg) # noqa: TRY002, TRY301
202
  except Exception: # noqa: BLE001
203
  return None
204
 
205
+
206
  @cachetools.cached(
207
  cache=cachetools.TTLCache(maxsize=_CACHE_MAX_SIZE, ttl=_CACHE_TTL_SECONDS),
208
  )