find the last used port

in search func