Check if port is in use before assigning it