PortGenerator.py 605 B

1234567891011121314
  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. :param offest: default value, which is added to the two ASCII values
  9. :return: sum of two ASCII characters and the default value
  10. """
  11. firstLetter = random.choice(string.ascii_letters);
  12. lastLetter = random.choice(string.ascii_letters + string.digits);
  13. return (offset + ord(firstLetter) * ord(lastLetter));