in reply to host with multiple ip addresses

In Perl, it is the same thing, just call gethostbyname. There is no need to connect to the remote.

You talk to DNS and not the remote to get the ip address.

If my PC is called "blah", I just do:

gethostbyname("blah");