Handle different number of hostnames and ports