This code is duplicated in several places, creating a method in AvailableSocketPorts.