I think that was done by:
1. Logic and the intelligence reports,
2. Strict BdU orders as what is and what is not a valid target,
3. Shadowing the target for a long time,
4. Radio listening,
5. Ship's shape and noise.
But I can only imagine, how they did it, as I don't have any sources for what I just wrote. What makes me quite sure that I'm not much mistaken is the fact, that they actually sunk quite many of neutral ships "by accident".