Created
September 6, 2016 21:02
-
-
Save privatwolke/c86b497d73c9738e23ed4dc8fc2bf7d3 to your computer and use it in GitHub Desktop.
Create port number based on application name
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
from binascii import crc32 | |
def port_number(app_name, min_port=49152, max_port=65535): | |
""" | |
Returns a port number based on the given app_name which falls in the range | |
[min_port, max_port]. | |
""" | |
checksum = crc32(app_name) & 0xffffffff | |
scale = max_port - min_port | |
return int((checksum / float(0xffffffff)) * scale + min_port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment