How to resolve a name/IP ?

D

Doublehp

Hello

I would like to have the most simple, and shortest possible code to
resolve a machine name, and get it's IP, possibly specifying the DNS I
want to use.

Just a function that will take as argument google.com, and return me
66.249.92.104

Thanks.
 
N

Nobody

I believe you might be looking for the Berkeley Sockets
"gethostbyname" function.

This has been superseded by getaddrinfo(), which has more features (e.g.
the ability to return IPv6 addresses).
Getting it from a specific DNS server would involve more work.

And is usually the wrong approach, as it bypasses any other name
resolution methods (/etc/hosts, NIS, WINS, etc). Also, you shouldn't
assume that you will be able to communicate directly with arbitrary DNS
servers; it's fairly common for firewalls to block port 53 traffic for
anything other than explicitly specified processes or hosts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top