C语言根据域名得到IP地址
#include <>
#include <>
#include <>
#include <>
#include <>
#include <sys/>
#include <>
#include <arpa/>
int get_ips_by_domain(const char * const domain){
struct hostent *_hostent = NULL;
_hostent = gethostbyname(domain);
int i = 0;
while(_hostent->h_addr_list[i] != NULL){
char *ipaddr = inet_ntoa(*((struct in_addr *)_hostent->h_addr_list[i]));
printf("ip addr%d: %s\n",i+1,ipaddr);
i++;
}
return 0;
}
int main(int argc, char const *argv[])
{
get_ips_by_domain("");
return 0;
}