Python: add utility function for retrieving port redirection