peachyontop

Packet Lag Switch

May 28th, 2025
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. import pydivert
  2. import time
  3.  
  4. DELAY_MS = 200
  5. DELAY_SECONDS = DELAY_MS / 1000
  6. LIMIT = 20
  7. FILTER = "outbound and udp and udp.DstPort == 27015"
  8.  
  9. queue = []
  10.  
  11. with pydivert.WinDivert(FILTER) as w:
  12.     print(f"[*] Fake lag active ({DELAY_SECONDS:.3f} sec) with packet limit {LIMIT}...")
  13.  
  14.     while True:
  15.         try:
  16.             packet = w.recv()
  17.             send_time = time.time() + DELAY_SECONDS
  18.             queue.append((send_time, packet))
  19.         except Exception as e:
  20.             print(f"Recv error: {e}")
  21.  
  22.         now = time.time()
  23.         ready_packets = [p for p in queue if p[0] <= now]
  24.         queue = [p for p in queue if p[0] > now]
  25.  
  26.         for _, pkt in ready_packets:
  27.             try:
  28.                 w.send(pkt)
  29.             except Exception as e:
  30.                 print(f"Send error: {e}")
  31.  
  32.         if len(queue) >= LIMIT:
  33.             _, pkt = queue.pop()
  34.             try:
  35.                 w.send(pkt)
  36.             except Exception as e:
  37.                 print(f"Send error: {e}")
  38.  
  39.         time.sleep(0.001)
Advertisement
Add Comment
Please, Sign In to add comment