Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TCP_USER_TIMEOUT and SYN-SENT
import socket
import os
import subprocess
import shlex
import time
import atexit
import signal
tcpdump_bin = os.popen('which tcpdump').read().strip()
def tcpdump_start(port):
p = subprocess.Popen(shlex.split('%s -B 16384 --packet-buffered -n -ttttt -i any port %s' % (tcpdump_bin, port)))
time.sleep(1)
def close():
p.send_signal(signal.SIGINT)
p.wait()
p.close = close
atexit.register(close)
return p
port = 1234
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
c.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, 5*1000)
tcpdump_start(port)
c.connect(('244.0.0.1', port))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment