import json import asyncio import socket from aiohttp import ClientSession from concurrent.futures import ThreadPoolExecutor def reverse_dns_lookup_sync(ip): """ Perform a reverse DNS lookup (synchronous, for multithreading). """ try: hostname = socket.gethostbyaddr(ip)[0] return hostname except socket.herror: return None async def reverse_dns_lookup(ip, executor): """ Perform a reverse DNS lookup using a thread pool. """ print(f"Performing DNS lookup for IP: {ip}") loop = asyncio.get_event_loop() hostname = await loop.run_in_executor(executor, reverse_dns_lookup_sync, ip) if hostname: print(f"DNS lookup successful for IP {ip}: {hostname}") else: print(f"DNS lookup failed for IP: {ip}") return hostname async def fetch_website_info(session, ip, hostname): """ Fetch website title and description from the IP. """ print(f"Fetching website info for IP: {ip} (Hostname: {hostname or 'Unknown'})") endpoints = [f"http://{ip}", f"http://{hostname}" if hostname else None] for url in filter(None, endpoints): try: print(f"Trying URL: {url}") async with session.get(url, timeout=10) as response: if response.status == 200: print(f"Successfully fetched data from {url}") html = await response.text() title = ( html.split("