i am using visual c++,
I want to get a domain ip address from domain name..
how do i get it..
i already tried gethostbyname function…
here my code…
HOSTENT* remoteHost;
IN_ADDR addr;
hostName = "domainname.com";
printf("Calling gethostbyname with %s\n", hostName);
remoteHost =gethostbyname(hostName);
memcpy(&addr.S_un.S_addr, remoteHost->h_addr, remoteHost->h_length);
printf("The IP address is: %s\n", inet_ntoa(addr));
But i get a wrong ip address.
Here’s complete source code to a little utility I find handy at times (I’ve named it “resolve”). All it does is resolve a domain name to a numeric IP (v4) address, and print it out. As-is, it’s for Windows — for Linux (or similar) you’d just need to get rid of the
use_WSAclass (and object thereof).This also uses the
infix_ostream_iteratorI’ve posted previously.