I'm trying to run the curl command in a loop with a range of ports, such that the loop runs for 2000 times, and after every 5 source ports used the range is re-used from port number 4000. But after the first 5 ports, I'm seeing a bind failed error because curl keeps these old connections for a while. Is there any way I can remove old connections and again restart the loop?
for i in {1...2000}
do
curl --local-port 4000-4005 http://10.52.26.22 -m 1
sleep 1
done