PortGenerator.py 469 B

123456789101112
  1. import random
  2. import string
  3. def gen_random_server_port(offset: int=2199):
  4. """
  5. Generates a valid random first and last character for a bots hostname
  6. and computes a port from these two characters.
  7. The default offset is chosen from a Sality implementation in 2011
  8. """
  9. firstLetter = random.choice(string.ascii_letters);
  10. lastLetter = random.choice(string.ascii_letters + string.digits);
  11. return (offset + ord(firstLetter) * ord(lastLetter));