Created
September 25, 2019 08:36
-
-
Save majek/b4ad53c5795b226d62fad1fa4a87151a to your computer and use it in GitHub Desktop.
TCP_USER_TIMEOUT and SYN-SENT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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