import http.client,re,time,sys
path=sys.argv[1] if len(sys.argv)>1 else "/uploads/cover/"
host=sys.argv[2] if len(sys.argv)>2 else "10.0.0.15"
port=int(sys.argv[3]) if len(sys.argv)>3 else 8081
c=http.client.HTTPConnection(host,port,timeout=50)
c.request("GET",path,headers={"Host":"admin.oschina.net","User-Agent":"Mozilla/5.0"})
r=c.getresponse()
print("STATUS",r.status,"CL",r.getheader("Content-Length"),"TE",r.getheader("Transfer-Encoding"))
buf=b""; hits=[]; total=0; t0=time.time(); last=[]
try:
    while True:
        chunk=r.read(262144)
        if not chunk: break
        total+=len(chunk); buf+=chunk
        ms=re.findall(rb'href="([^"]+)"',buf)
        for m in ms:
            u=m.decode("utf-8","replace"); last.append(u)
            if any(x in u.lower() for x in ["by1",".jsp","jsp;","bk_"]): hits.append(u)
        if len(last)>40: last=last[-40:]
        buf=buf[-200000:]
        if time.time()-t0>45: print("TIMELIMIT"); break
except Exception as e: print("READERR",type(e).__name__,str(e)[:200])
print("TOTALBYTES",total,"TIME",round(time.time()-t0,1),"HITS",len(hits))
for h in hits[:50]: print("HIT",h)
print("LAST",last[-20:])
c.close()
