import asyncio
import sys

import aiohttp

UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/131.0"}


async def one(sess, sem, ip, port, path):
    scheme = "https" if port == "443" else "http"
    url = "%s://%s:%s%sindex_sso.php" % (scheme, ip, port, path)
    try:
        async with sem:
            async with sess.get(url, ssl=False, allow_redirects=False) as r:
                loc = r.headers.get("Location", "")
                return "%s:%s%s %d loc=%s" % (ip, port, path, r.status, loc[:70])
    except Exception as e:
        return "%s:%s%s err %s" % (ip, port, path, type(e).__name__)


async def main():
    rows = []
    for line in sys.stdin:
        f = line.rstrip("\n").split("\t")
        if len(f) >= 3:
            rows.append((f[0], f[1], f[2]))
    sem = asyncio.Semaphore(10)
    to = aiohttp.ClientTimeout(total=12, connect=5, sock_read=10)
    async with aiohttp.ClientSession(timeout=to, headers=UA,
                                     connector=aiohttp.TCPConnector(limit=0, ssl=False)) as s:
        res = await asyncio.gather(*[one(s, sem, *r) for r in rows])
    for x in res:
        print(x)


asyncio.run(main())
