Created
December 21, 2018 10:23
-
-
Save henix/8e7c3129295685f423efeb7c56988aa3 to your computer and use it in GitHub Desktop.
Get a port number for you app. Usage: hashport.sh my-app
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
#!/bin/sh | |
[ $# -ne 1 ] && echo "Usage: $0 name" && exit 1 | |
p=$(printf "%d" "0x$(printf "%s" "$1" | md5sum | head -c 4)") | |
# pratical port range is 1024 ~ 65535 (for app that don't require root) | |
# 64499 is the first prime number that less than 65535 - 1024 | |
port=$((p % 64499 + 1024)) | |
echo "$port" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment