#!/usr/bin/env python3 # python3 -I winchk.py p1.txt import asyncio, socket, struct, sys TIMEOUT, WORKERS = 3.0, 500 OFF = 228 # offset of tcpi_snd_wnd in struct tcp_info (Linux >=5.4) async def worker(q): while True: item = await q.get() if item is None: q.task_done(); return ip, port = item try: r, w = await asyncio.wait_for(asyncio.open_connection(ip, port), TIMEOUT) try: s = w.get_extra_info("socket") buf = s.getsockopt(socket.IPPROTO_TCP, socket.TCP_INFO, 512) if len(buf) >= OFF + 4: wnd = struct.unpack_from(" 1000: # real stack, not win=3 print(f"{ip}:{port}\tsnd_wnd={wnd}", flush=True) finally: w.close() except Exception: pass finally: q.task_done() async def main(path): q = asyncio.Queue(maxsize=WORKERS * 4) ws = [asyncio.create_task(worker(q)) for _ in range(WORKERS)] with open(path) as f: for ln in f: ln = ln.strip().replace(" ", ":") if ln: ip, port = ln.rsplit(":", 1) await q.put((ip, int(port))) await q.join() for _ in ws: await q.put(None) await asyncio.gather(*ws) asyncio.run(main(sys.argv[1]))