code: def unused_port(hostname):
      
      with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
          s.bind((hostname, 0))
          return s.getsockname()[1]
docs: Return a port that is unused on the current host.