[ACCEPTED]-Sending a reset in TCP/IP Socket connection-reset
Turn the SO_LINGER socket option on and 5 set the linger time to 0 seconds. This 4 will cause TCP to abort the connection when 3 it is closed, flush the data and send a 2 RST. See section 7.5 and example 15.21 1 in UNP.
def client(host, port): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) s.connect((host, port)) l_onoff = 1 l_linger = 0 s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', l_onoff, l_linger)) # send data here s.close()
If you want to implement your own behavior 3 over connections I think you should try 2 using Scapy. It is a really useful library/tool. It 1 lets you play with IP/TCP/UDP/ICMP packages.
To send an RST on a TCP connection, set 4 the
SO_LINGER option to
true with a zero timeout, then 3 close the socket. This resets the connection. I 2 have no idea how to do that in Python, or 1 indeed whether you can even do it.
More Related questions