import asyncio, sys

import aiohttp

UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36"


async def one(sess, ip, sem):
    async with sem:
        try:
            async with sess.get("https://%s/" % ip, ssl=False, allow_redirects=False, headers={"User-Agent": UA}) as r:
                b = await r.read(4000)
                return "%s\t%d\t%s\t%s" % (ip, r.status, (r.headers.get("Location") or "")[:50], (r.headers.get("Server") or "")[:20])
        except Exception as e:
            return "%s\tERR\t%s" % (ip, type(e).__name__)


async def main():
    ips = [l.split()[-1] for l in open(sys.argv[1]) if l.strip()]
    sem = asyncio.Semaphore(100)
    conn = aiohttp.TCPConnector(limit=0, ssl=False, force_close=True)
    to = aiohttp.ClientTimeout(total=10, connect=6, sock_read=8)
    async with aiohttp.ClientSession(timeout=to, connector=conn) as sess:
        res = await asyncio.gather(*[one(sess, ip, sem) for ip in ips])
    for r in res:
        print(r)


asyncio.run(main())
