To get a random available port in your *nix-based machine
For example, If I want to get a random port from the 3000-3999 port pool, I would run the following command in the terminal:
comm -23 <(seq 3000 3999 | sort) <(ss -tan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1
comm -23 <(seq 3000 3999 | sort) <(ss -tan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1
Comments
Post a Comment