For testing purpose, I need to send POST requests to Google Cloud HTTP Load Balancer from Postman with Google Developer Tools enabled (tracking network activity).
Every request should be made with a different connection.
So, I suppose to use tcpkill
utility:
$ tcpkill -9 "dst XXX.XXX.XXX.XXX and dst port 443"
But, eventually, this leads to closing every connection before it would be established. So, Postman gets a connection error.
So, the question is: how to finish connection only after it was ESTABLISHED and POST request was sent to the server?
Thanks in advance, comrades.
You can't do that with tcpkill since this program requires traffic to kill the connection and does not support filters using connection state. So, if you run tcpkill before the connections are established, they will be killed before connecting; and if you run tcpkill after connections are established they won't be killed if there is no traffic since tcpkill requires a valid sequence number to send a RST.
You can try killcx filtering established connections with ss or netstat, something like this:
#!/bin/bash
dst=$1
port=$2
peer_addrs=$(ss -t state established dst ${dst} dport = :${port} |
tail -n +2 | awk '{print $4}' | cut -d : -f 1)
for addr in ${peer_addrs}; do
echo "killing ${addr}:${port}"
killcx ${addr}:${port}" &
sleep 2
killall -9 killcx
done
You will need to run this script periodically in a loop using watch or similar and, of course, this won't kill connections immediately after they are established but a little bit later when the cycle finds the connection.