Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pydivert
- import time
- DELAY_SECONDS = 200 # DELAY MS
- DELAY_SECONDS /= 1000 # CONVERT TO SECONDS
- LIMIT = 20 # MAX PACKETS TO DELAY
- filter_str = "outbound and udp and udp.DstPort == 27015" # PORT MUST BE THE SAME AS THE SERVER
- queue = [] # WE PUT ALL PACKETS HERE
- with pydivert.WinDivert(filter_str) as w: # START LISTENING
- print(f"[*] Fake lag is active ({DELAY_SECONDS} sec and with packet limit {LIMIT})...")
- while True:
- try:
- packet = w.recv() # DELAYING PACKET
- send_time = time.time() + DELAY_SECONDS #CALCULATE SEND TIME (CURRENT_TIME + DELAY)
- queue.append((send_time, packet)) # APPENDING FOR QUEUE LIST
- except Exception as e:
- print(f"recv error: {e}")
- now = time.time() # CURRENT TIME
- ready = [p for p in queue if p[0] <= now] #READY PACKETS, IF (CURRENT_TIME <= SEND TIME)
- queue = [p for p in queue if p[0] > now] #ELSE
- for _, pkt in ready:
- try:
- w.send(pkt) #SEND ALL PACKETS IN READY LIST
- except Exception as e:
- print(f"send error: {e}")
- if len(queue) >= LIMIT: #CHECKING SIZE OF QUEUE, IF THERE MORE THAN LIMIT, WE SEND LAST PACKET
- _, pkt = queue[-1]
- w.send(pkt)
- time.sleep(0.001) # DONT KILL YOUR CPU :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement