-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-idle.py
47 lines (33 loc) · 1005 Bytes
/
test-idle.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
import io
import os
import select
import socket
import time
import utils
utils.new_ns()
port = 1
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
s.bind(('127.0.0.1', port))
s.listen(16)
tcpdump = utils.tcpdump_start(port)
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
c.connect(('127.0.0.1', port))
if True:
# c.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, 33500)
c.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
c.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 5) # seconds
c.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 3) # seconds
c.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 3)
t0 = time.time()
utils.drop_start(dport=port)
utils.drop_start(sport=port)
time.sleep(2)
utils.ss(port)
poll = select.poll()
poll.register(c, select.POLLIN)
poll.poll()
utils.ss(port)
e = c.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
print("[ ] SO_ERROR = %s" % (e,))
t1 = time.time()
print("[ ] took: %f seconds" % (t1-t0,))