Last active
December 19, 2018 10:01
-
-
Save fstefanov/ff4dcec7ded59514421bf944d1bb9a6f to your computer and use it in GitHub Desktop.
Get two free random ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original version https://superuser.com/a/1293762/622572 | |
export SERVER_PORT_SERVICE SERVER_PORT_ADMIN | |
readarray -t RANDOM_PORTS < <( | |
comm -23 <(seq 65000 65535) \ | |
<(ss -ant \ | |
| tail -n +1 \ | |
| awk '{print $4}' \ | |
| awk -F ":" '{print $NF}' \ | |
| sort | uniq) \ | |
| sort -R | head -n 2) | |
read SERVER_PORT_SERVICE SERVER_PORT_ADMIN <<< "${RANDOM_PORTS[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment