Python implementation of hashport, a text-to-port hashing function within the dynamic range (49152-65535).
Hashport is a function that generates a port number using a deterministic hashing algorithm. It takes a string input as the name of the project or entity that requires a port number and returns an integer value that falls within the range of ports typically used for dynamic assignments (49152 to 65535).
The function uses the SHA-256 algorithm to generate a hash of the input string. The resulting hash is then converted to an integer, and the integer is scaled to the desired range using modular arithmetic.
Hashport is useful in scenarios where a fixed and deterministic port assignment is required. By hashing the project name, the same input will always generate the same output, ensuring consistency and predictability in port assignments.
pip install -U hashport
from hashport import hashport
port = hashport('project-name')
hashport project-name