int asLookup(char* ip) { char* response = NULL; int asNum = 0; char server[256]; int i = 0; strcpy(server, "whois.iana.org\0"); /* Sometimes we need to ask 3 different servers.. */ while (asNum == 0 && i <= 3) { i++; if ( whois_query(server, ip, &response) ) { free(response); return 0; } asNum = getAsNumber( response, server, sizeof(server) ); } free(response); return asNum; }
/** Get the whois content of an ip by selecting the correct server */ void get_whois(char *ip , char **data) { char *wch = NULL, *pch , *response = NULL; if(whois_query("whois.iana.org" , ip , &response)) { printf("Whois query failed"); } pch = strtok(response , "\n"); while(pch != NULL) { //Check if whois line wch = strstr(pch , "whois."); if(wch != NULL) { break; } //Next line please pch = strtok(NULL , "\n"); } if(wch != NULL) { printf("\nWhois server is : %s" , wch); whois_query(wch , ip , data); } else { *data = malloc(100); strcpy(*data , "No whois data"); } return; }