Skip to content

Instantly share code, notes, and snippets.

@dnyall
Last active August 13, 2024 13:44
Show Gist options
  • Select an option

  • Save dnyall/a2b42b155b21fdc2859cd9442689cb0a to your computer and use it in GitHub Desktop.

Select an option

Save dnyall/a2b42b155b21fdc2859cd9442689cb0a to your computer and use it in GitHub Desktop.
get random unused port (bash)
ruby -e 'require "socket"; puts Addrinfo.tcp("", 0).bind {|s| s.local_address.ip_port }'
# OR
comm -23 \
<(seq "$FROM" "$TO") \
<(ss -tan | awk '{print $4}' | cut -d':' -f2 | grep '[0-9]\{1,5\}' | sort -n | uniq) \
| shuf | head -n "$HOWMANY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment