Skip to content

Instantly share code, notes, and snippets.

@privatwolke
Created September 6, 2016 21:02
Show Gist options
  • Save privatwolke/c86b497d73c9738e23ed4dc8fc2bf7d3 to your computer and use it in GitHub Desktop.
Save privatwolke/c86b497d73c9738e23ed4dc8fc2bf7d3 to your computer and use it in GitHub Desktop.
Create port number based on application name
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