Re:Exploiting URL Parser in Programming Languages (2017) [pdf]
by jkarneges on Tuesday September 11, 2018 @11:50AM
(#17960793)
IPv6: blacklist similar address ranges. Multiple A records: be sure to check against each record before connecting.
Connecting first and then checking the remote IP before sending anything could work I suppose, but I think you'd still need to check against a blacklist.
I would rather let the OS connect the way it prefers and once it is connected, check that the remote is a legit IP address before sending anything.