79512718

Date: 2025-03-16 14:45:40
Score: 0.5
Natty:
Report link

For now, I have found the least optimal solution in conntrack.

sudo conntrack -E -p $PROTOCOL --dport $PORT

By consuming the lines including [NEW] and [DESTROY], I can track the number of "active" connections to the server and pause the process when the connection number equals zero. This option is not great because it is linux-specific, requires root (or CAP_NET_ADMIN), and requires another conntrack process for every port, protocol, and IP version combination. The last point can probably be improved by using the conntrack library instead, but I'd still like to see other answers that don't have these requirements.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: josephsmendoza