-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-syn-sent.py
53 lines (41 loc) · 973 Bytes
/
test-syn-sent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import io
import os
import select
import socket
import time
import utils
utils.new_ns()
port = 1
tcpdump = utils.tcpdump_start(port)
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
t0 = time.time()
utils.drop_start(dport=port)
if False:
c.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, 5*1000)
# speedup
# os.system('sysctl net.ipv4.tcp_syn_retries=4')
if False:
c.setblocking(False)
try:
c.connect(('127.0.0.1', port))
except io.BlockingIOError:
pass
c.setblocking(True)
utils.ss(port)
time.sleep(1)
utils.ss(port)
time.sleep(3)
utils.ss(port)
poll = select.poll()
poll.register(c, select.POLLOUT)
poll.poll()
utils.ss(port)
else:
try:
c.connect(('127.0.0.1', port))
except Exception as e:
print(e)
e = c.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
print("[ ] SO_ERROR = %s" % (e,))
t1 = time.time()
print("[ ] connect took %fs" % (t1-t0,))