import asyncio, socket
import aiohttp

ESG = ["107.1.159.8", "158.123.195.9", "162.17.33.186", "168.99.1.23",
       "192.153.31.25", "199.73.81.229", "206.82.23.206", "216.147.227.66"]
ALL = [l.split("\t")[0] for l in open("/root/recon/bdui_full.tsv") if l.strip()]


def rdns(ip):
    try:
        return socket.gethostbyaddr(ip)[0]
    except Exception:
        return ""


async def main():
    loop = asyncio.get_running_loop()
    tout = aiohttp.ClientTimeout(total=12, connect=6, sock_read=8)
    async with aiohttp.ClientSession(timeout=tout, headers={"User-Agent": "Mozilla/5.0"}) as s:
        for ip in sorted(set(ALL)):
            host = await loop.run_in_executor(None, rdns, ip)
            title = ""
            try:
                async with s.get(f"https://{ip}/cgi-mod/index.cgi", ssl=False) as r:
                    h = r.headers.get("Server", "")
            except Exception:
                h = ""
            tag = "ESG?" if ip in ESG else ""
            print(f"{ip:16s} {tag:5s} {h[:24]:24s} {host[:70]}")

asyncio.run(main())
