Client or server.
Why not server side? The server is delivering these links to the client and it should not be delivering any old un-vetted crap even if that means the link has to be resolved in order to vet the underlying IP. Tedious and convoluted? Yup, but only because webpages have become such a chaotic Cluster. Time for more engineering and less code-slinging.