GetCorrectPort

finished getcorrectport (not tested)