Fix issue MR-495 - Having a negative range in port scan creates memory exhaustion.

Make minor improvements to the port scan functionality.