49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
import socket
|
|||
|
|
import time
|
||
|
|
|
||
|
|
PORT_LIST = [511, 515, 516, 517, 518, 519, 520, 1000, 2000, 5000, 6060, 8000, 8300, 9000, 9200, 10008, 12345]
|
||
|
|
TIMEOUT = 30.0 # seconds
|
||
|
|
|
||
|
|
print("Starting background UDP sniffer on ports:", PORT_LIST)
|
||
|
|
print("Listening for 30 seconds...")
|
||
|
|
|
||
|
|
sockets = []
|
||
|
|
for port in PORT_LIST:
|
||
|
|
try:
|
||
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||
|
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||
|
|
s.bind(("0.0.0.0", port))
|
||
|
|
s.setblocking(False)
|
||
|
|
sockets.append((s, port))
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Could not bind to UDP port {port}: {e}")
|
||
|
|
|
||
|
|
start_time = time.time()
|
||
|
|
captured = []
|
||
|
|
|
||
|
|
while time.time() - start_time < TIMEOUT:
|
||
|
|
for s, port in sockets:
|
||
|
|
try:
|
||
|
|
data, addr = s.recvfrom(4096)
|
||
|
|
# Log from any sender that is not local loopback
|
||
|
|
if addr[0] != "127.0.0.1":
|
||
|
|
event = f"[UDP Port {port}] Received {len(data)} bytes from {addr[0]}:{addr[1]} - Hex: {data.hex()}"
|
||
|
|
print(event)
|
||
|
|
captured.append(event)
|
||
|
|
except BlockingIOError:
|
||
|
|
pass
|
||
|
|
except Exception as e:
|
||
|
|
pass
|
||
|
|
time.sleep(0.01)
|
||
|
|
|
||
|
|
for s, port in sockets:
|
||
|
|
s.close()
|
||
|
|
|
||
|
|
print("Finished UDP sniff.")
|
||
|
|
with open("C:\\Users\\Dell\\.gemini\\antigravity-ide\\brain\\17f86d9d-29a1-4f54-b185-045db1a407b4\\scratch\\udp_sniff_now_results.txt", "w") as f:
|
||
|
|
f.write("UDP Sniffing results:\n")
|
||
|
|
if not captured:
|
||
|
|
f.write("No UDP packets captured.\n")
|
||
|
|
for event in captured:
|
||
|
|
f.write(event + "\n")
|