Update port lookup.

Offers improved safety and handles multiple ways of specifying the ports.