How to find multiple ip address for one domain name (with c programming)
Some domain’s serve under multiple ip addresses for example google.com
if you want to query this ip addresses then you can use this code block
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr,"Usage: ./app www.google.com\n");
exit(1);
}
struct hostent *hp = gethostbyname(argv[1]);
if (hp == NULL) {
fprintf(stderr,"query failed\n");
exit(1);
} else {
unsigned int i=0;
while ( hp -> h_addr_list[i] != NULL) {
printf( "%d -> %s ",i, inet_ntoa( *( struct in_addr*)( hp -> h_addr_list[i])));
i++;
}
exit(0);
}
}
Buy me a beer
