Spaces:
Sleeping
Sleeping
File size: 1,292 Bytes
6ed25f9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import asyncio
import aiodns
from urllib.parse import urlparse
# Simple highly-reputable baseline list
TOP_DOMAINS = {"google.com", "apple.com", "microsoft.com", "amazon.com", "netflix.com"}
async def analyze_network_footprint(url: str) -> float:
score = 0.0
hostname = urlparse(url).hostname or ""
if not hostname: return 0.0
# Base domain extraction (e.g., www.google.com -> google.com)
domain_parts = hostname.split('.')
base_domain = ".".join(domain_parts[-2:]) if len(domain_parts) >= 2 else hostname
if base_domain in TOP_DOMAINS:
return 0.0 # Highly reputable infrastructure bypasses structural anomaly traps
resolver = aiodns.DNSResolver()
try:
a_records = await resolver.query(hostname, 'A')
if len(a_records) > 3:
score += 0.3
if a_records:
first_ip = a_records[0].host
ip_parts = first_ip.split('.')
arpa_addr = f"{'.'.join(reversed(ip_parts))}.in-addr.arpa"
try:
await resolver.query(arpa_addr, 'PTR')
except aiodns.error.DNSError:
score += 0.3
except aiodns.error.DNSError:
score += 0.8
return min(score, 1.0) |