int main(int argc, char *argv[]) { FILE *f; GeoIP *gi; char *org; char host[50]; gi = GeoIP_open("../data/GeoIPISP.dat", GEOIP_STANDARD); if (gi == NULL) { fprintf(stderr, "Error opening database\n"); exit(1); } f = fopen("isp_test.txt", "r"); if (f == NULL) { fprintf(stderr, "Error opening isp_test.txt\n"); exit(1); } while (fscanf(f, "%s", host) != EOF) { org = GeoIP_org_by_name(gi, (const char *)host); if (org != NULL) { printf("%s\t%s\n", host, _mk_NA(org)); free(org); } } fclose(f); GeoIP_delete(gi); return 0; }
/* Use the GeoIP API to locate an IP address */ char *GeoIPLookup(char *ip) { GeoIP *gi; GeoIPRecord *gir; char buffer[OS_SIZE_1024 +1]; unsigned long longip; /* Dumb way to detect an IPv6 address */ if (strchr(ip, ':')) { /* Use the IPv6 DB */ gi = GeoIP_open(Config.geoip_db_path, GEOIP_INDEX_CACHE); if (gi == NULL) { merror(INVALID_GEOIP_DB, ARGV0, Config.geoip6_db_path); return("Unknown"); } gir = GeoIP_record_by_name_v6(gi, (const char *)ip); } else { /* Use the IPv4 DB */ /* If we have a RFC1918 IP, do not perform a DB lookup (performance) */ longip = StrIP2Int(ip); if (longip == 0 ) return("Unknown"); if ((longip & NETMASK_8) == RFC1918_10 || (longip & NETMASK_12) == RFC1918_172 || (longip & NETMASK_16) == RFC1918_192) return(""); gi = GeoIP_open(Config.geoip_db_path, GEOIP_INDEX_CACHE); if (gi == NULL) { merror(INVALID_GEOIP_DB, ARGV0, Config.geoip_db_path); return("Unknown"); } gir = GeoIP_record_by_name(gi, (const char *)ip); } if (gir != NULL) { sprintf(buffer,"%s,%s,%s", _mk_NA(gir->country_code), _mk_NA(GeoIP_region_name_by_code(gir->country_code, gir->region)), _mk_NA(gir->city) ); GeoIP_delete(gi); return(buffer); } GeoIP_delete(gi); return("Unknown"); }
int geoiplookup (GeoIP * gi, char *hostname, int i, struct geo_output_struct *geo_output) { GeoIPRecord *gir; uint32_t ipnum; ipnum = _GeoIP_lookupaddress (hostname); if (ipnum == 0) { pmesg(LOG_ERROR,__FILE__,__LINE__, "%s: can't resolve hostname ( %s ) [keep this code for debug -1]\n", GeoIPDBDescription[i], hostname); return -1; } if (GEOIP_CITY_EDITION_REV1 == i) // it should be always true { gir = GeoIP_record_by_ipnum (gi, ipnum); if (NULL == gir) { pmesg(LOG_ERROR,__FILE__,__LINE__,"%s: IP Address not found [keep this code for debug -3]\n",GeoIPDBDescription[i]); return -3; } else { sprintf (geo_output->country_code, "%s", gir->country_code); sprintf (geo_output->region, "%s",_mk_NA (gir->region)); sprintf (geo_output->city,"%s",_mk_NA (gir->city)); sprintf (geo_output->postal_code,"%s", _mk_NA (gir->postal_code)); geo_output->latitude=gir->latitude; geo_output->longitude=gir->longitude; geo_output->metro_code=gir->metro_code; geo_output->area_code=gir->area_code; //_say_range_by_ip (gi, ipnum); GeoIPRecord_delete (gir); } } else { pmesg(LOG_ERROR,__FILE__,__LINE__,"Some problem with the current release [keep this code for debug -2 ver:%d]\n",i); return -2; } return 0; }
int main(int argc, char *argv[]) { FILE *f; GeoIP *gi; GeoIPRecord *gir; int generate = 0; char host[50]; const char *time_zone = NULL; char **ret; if (argc == 2) { if (!strcmp(argv[1], "gen")) { generate = 1; } } gi = GeoIP_open("../data/GeoIPCity.dat", GEOIP_INDEX_CACHE); if (gi == NULL) { fprintf(stderr, "Error opening database\n"); exit(1); } f = fopen("city_test.txt", "r"); if (f == NULL) { fprintf(stderr, "Error opening city_test.txt\n"); exit(1); } while (fscanf(f, "%s", host) != EOF) { gir = GeoIP_record_by_name(gi, (const char *)host); if (gir != NULL) { ret = GeoIP_range_by_ip(gi, (const char *)host); time_zone = GeoIP_time_zone_by_country_and_region(gir->country_code, gir->region); printf("%s\t%s\t%s\t%s\t%s\t%s\t%f\t%f\t%d\t%d\t%s\t%s\t%s\n", host, _mk_NA(gir->country_code), _mk_NA(gir->region), _mk_NA(GeoIP_region_name_by_code (gir->country_code, gir->region)), _mk_NA(gir->city), _mk_NA(gir->postal_code), gir->latitude, gir->longitude, gir->metro_code, gir->area_code, _mk_NA(time_zone), ret[0], ret[1]); GeoIP_range_by_ip_delete(ret); GeoIPRecord_delete(gir); } } GeoIP_delete(gi); fclose(f); return 0; }
int main(int argc, char *argv[]) { FILE *f; GeoIP *gi; char *domain; char host[50]; char **ret; gi = GeoIP_open("../data/GeoIPDomain.dat", GEOIP_INDEX_CACHE); if (gi == NULL) { fprintf(stderr, "Error opening database\n"); exit(1); } f = fopen("domain_test.txt", "r"); if (f == NULL) { fprintf(stderr, "Error opening domain_test.txt\n"); exit(1); } printf("IP\tdomain\tnetmask\tbeginIp\tendIp\n"); while (fscanf(f, "%s", host) != EOF) { domain = GeoIP_name_by_name(gi, (const char *)host); if (domain != NULL) { ret = GeoIP_range_by_ip(gi, (const char *)host); printf("%s\t%s\t%d\t%s\t%s\n", host, _mk_NA(domain), GeoIP_last_netmask(gi), ret[0], ret[1]); GeoIP_range_by_ip_delete(ret); free(domain); } } fclose(f); GeoIP_delete(gi); return 0; }
int main (int argc, char* argv[]) { FILE *f; GeoIP * gi; char * org; int generate = 0; char host[50]; if (argc == 2) if (!strcmp(argv[1],"gen")) generate = 1; gi = GeoIP_open("../data/GeoIPASNum.dat", GEOIP_STANDARD); if (gi == NULL) { fprintf(stderr, "Error opening database\n"); exit(1); } f = fopen("asnum_test.txt","r"); if (f == NULL) { fprintf(stderr, "Error opening asnum_test.txt\n"); exit(1); } while (fscanf(f, "%s", host) != EOF) { org = GeoIP_org_by_name (gi, (const char *)host); if (org != NULL) { printf("%s\t%s\n", host, _mk_NA(org)); } } GeoIP_delete(gi); return 0; }
void geoiplookup(GeoIP * gi, char *hostname, int i) { const char *country_code; const char *country_name; const char *domain_name; const char *asnum_name; int netspeed; int country_id; GeoIPRegion *region; GeoIPRecord *gir; const char *org; uint32_t ipnum; ipnum = _GeoIP_lookupaddress(hostname); if (ipnum == 0) { printf("%s: can't resolve hostname ( %s )\n", GeoIPDBDescription[i], hostname); }else { if (GEOIP_DOMAIN_EDITION == i) { domain_name = GeoIP_name_by_ipnum(gi, ipnum); if (domain_name == NULL) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s\n", GeoIPDBDescription[i], domain_name); _say_range_by_ip(gi, ipnum); free((void *)domain_name); } }else if (GEOIP_LOCATIONA_EDITION == i || GEOIP_ACCURACYRADIUS_EDITION == i || GEOIP_ASNUM_EDITION == i || GEOIP_USERTYPE_EDITION == i || GEOIP_REGISTRAR_EDITION == i || GEOIP_NETSPEED_EDITION_REV1 == i || GEOIP_COUNTRYCONF_EDITION == i || GEOIP_CITYCONF_EDITION == i || GEOIP_REGIONCONF_EDITION == i || GEOIP_POSTALCONF_EDITION == i) { asnum_name = GeoIP_name_by_ipnum(gi, ipnum); if (asnum_name == NULL) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s\n", GeoIPDBDescription[i], asnum_name); _say_range_by_ip(gi, ipnum); free((void *)asnum_name); } }else if (GEOIP_COUNTRY_EDITION == i) { country_id = GeoIP_id_by_ipnum(gi, ipnum); if (country_id < 0 || country_id >= (int)GeoIP_num_countries()) { printf("%s: Invalid database\n", GeoIPDBDescription[i]); return; } country_code = GeoIP_country_code[country_id]; country_name = GeoIP_country_name[country_id]; if (country_id == 0) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s, %s\n", GeoIPDBDescription[i], country_code, country_name); _say_range_by_ip(gi, ipnum); } }else if (GEOIP_REGION_EDITION_REV0 == i || GEOIP_REGION_EDITION_REV1 == i) { region = GeoIP_region_by_ipnum(gi, ipnum); if (NULL == region || region->country_code[0] == '\0') { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s, %s\n", GeoIPDBDescription[i], region->country_code, region->region); _say_range_by_ip(gi, ipnum); } if (region) { GeoIPRegion_delete(region); } }else if (GEOIP_CITY_EDITION_REV0 == i) { gir = GeoIP_record_by_ipnum(gi, ipnum); if (NULL == gir) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s, %s, %s, %s, %s, %f, %f\n", GeoIPDBDescription[i], gir->country_code, _mk_NA( gir->region), _mk_NA(GeoIP_region_name_by_code(gir->country_code, gir->region)), _mk_NA(gir->city), _mk_NA( gir->postal_code), gir->latitude, gir->longitude); _say_range_by_ip(gi, ipnum); GeoIPRecord_delete(gir); } }else if (GEOIP_CITY_EDITION_REV1 == i) { gir = GeoIP_record_by_ipnum(gi, ipnum); if (NULL == gir) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s, %s, %s, %s, %s, %f, %f, %d, %d\n", GeoIPDBDescription[i], gir->country_code, _mk_NA( gir->region), _mk_NA(GeoIP_region_name_by_code(gir->country_code, gir->region)), _mk_NA(gir->city), _mk_NA( gir->postal_code), gir->latitude, gir->longitude, gir->metro_code, gir->area_code); _say_range_by_ip(gi, ipnum); GeoIPRecord_delete(gir); } }else if (GEOIP_ORG_EDITION == i || GEOIP_ISP_EDITION == i) { org = GeoIP_org_by_ipnum(gi, ipnum); if (org == NULL) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s\n", GeoIPDBDescription[i], org); _say_range_by_ip(gi, ipnum); free((void *)org); } }else if (GEOIP_NETSPEED_EDITION == i) { netspeed = GeoIP_id_by_ipnum(gi, ipnum); if (netspeed == GEOIP_UNKNOWN_SPEED) { printf("%s: Unknown\n", GeoIPDBDescription[i]); }else if (netspeed == GEOIP_DIALUP_SPEED) { printf("%s: Dialup\n", GeoIPDBDescription[i]); }else if (netspeed == GEOIP_CABLEDSL_SPEED) { printf("%s: Cable/DSL\n", GeoIPDBDescription[i]); }else if (netspeed == GEOIP_CORPORATE_SPEED) { printf("%s: Corporate\n", GeoIPDBDescription[i]); } _say_range_by_ip(gi, ipnum); } } }
void geoiplookup(GeoIP * gi, char *hostname, int i) { const char *country_code; const char *country_name; const char *asnum_name; int country_id; GeoIPRecord *gir; geoipv6_t ipnum; ipnum = _GeoIP_lookupaddress_v6(hostname); if (__GEOIP_V6_IS_NULL(ipnum)) { printf("%s: can't resolve hostname ( %s )\n", GeoIPDBDescription[i], hostname); }else { #if 0 if (GEOIP_DOMAIN_EDITION_V6 == i) { domain_name = GeoIP_name_by_name_v6(gi, hostname); if (domain_name == NULL) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s\n", GeoIPDBDescription[i], domain_name); } } #endif if (GEOIP_LOCATIONA_EDITION_V6 == i || GEOIP_ASNUM_EDITION_V6 == i || GEOIP_USERTYPE_EDITION_V6 == i || GEOIP_REGISTRAR_EDITION_V6 == i || GEOIP_DOMAIN_EDITION_V6 == i || GEOIP_ORG_EDITION_V6 == i || GEOIP_ISP_EDITION_V6 == i || GEOIP_NETSPEED_EDITION_REV1_V6 == i) { asnum_name = GeoIP_name_by_ipnum_v6(gi, ipnum); if (asnum_name == NULL) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s\n", GeoIPDBDescription[i], asnum_name); // _say_range_by_ip(gi, ipnum); } }else if (GEOIP_CITY_EDITION_REV0_V6 == i) { gir = GeoIP_record_by_ipnum_v6(gi, ipnum); if (NULL == gir) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s, %s, %s, %s, %f, %f\n", GeoIPDBDescription[i], gir->country_code, _mk_NA( gir->region), _mk_NA(gir->city), _mk_NA( gir->postal_code), gir->latitude, gir->longitude); } }else if (GEOIP_CITY_EDITION_REV1_V6 == i) { gir = GeoIP_record_by_ipnum_v6(gi, ipnum); if (NULL == gir) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s, %s, %s, %s, %f, %f, %d, %d\n", GeoIPDBDescription[i], gir->country_code, _mk_NA( gir->region), _mk_NA(gir->city), _mk_NA( gir->postal_code), gir->latitude, gir->longitude, gir->metro_code, gir->area_code); } }else if (GEOIP_COUNTRY_EDITION_V6 == i) { country_id = GeoIP_id_by_ipnum_v6(gi, ipnum); country_code = GeoIP_country_code[country_id]; country_name = GeoIP_country_name[country_id]; if (country_id == 0) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); }else { printf("%s: %s, %s\n", GeoIPDBDescription[i], country_code, country_name); } } } #if 0 else if (GEOIP_REGION_EDITION_REV0 == i || GEOIP_REGION_EDITION_REV1 == i) {
void geoiplookup(GeoIP * gi, char *hostname, int i) { const char *country_code; const char *country_name; const char *domain_name; const char *asnum_name; int netspeed; int country_id; GeoIPRegion *region; GeoIPRecord *gir; const char *org; uint32_t ipnum; ipnum = _GeoIP_lookupaddress(hostname); if (ipnum == 0) { printf("%s: can't resolve hostname ( %s )\n", GeoIPDBDescription[i], hostname); } else { if (GEOIP_DOMAIN_EDITION == i) { domain_name = GeoIP_name_by_ipnum(gi, ipnum); if (domain_name == NULL) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s\n", GeoIPDBDescription[i], domain_name); _say_range_by_ip(gi, ipnum); } } else if (GEOIP_LOCATIONA_EDITION == i || GEOIP_ACCURACYRADIUS_EDITION == i || GEOIP_ASNUM_EDITION == i || GEOIP_USERTYPE_EDITION == i || GEOIP_REGISTRAR_EDITION == i || GEOIP_NETSPEED_EDITION_REV1 == i ) { asnum_name = GeoIP_name_by_ipnum(gi, ipnum); if (asnum_name == NULL) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s\n", GeoIPDBDescription[i], asnum_name); _say_range_by_ip(gi, ipnum); } } else if (GEOIP_COUNTRY_EDITION == i) { country_id = GeoIP_id_by_ipnum(gi, ipnum); country_code = GeoIP_country_code[country_id]; country_name = GeoIP_country_name[country_id]; if (country_id == 0) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s, %s\n", GeoIPDBDescription[i], country_code, country_name); _say_range_by_ip(gi, ipnum); } } else if (GEOIP_REGION_EDITION_REV0 == i || GEOIP_REGION_EDITION_REV1 == i) { region = GeoIP_region_by_ipnum(gi, ipnum); if (NULL == region || region->country_code[0] == '\0' ) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s, %s\n", GeoIPDBDescription[i], region->country_code, region->region); _say_range_by_ip(gi, ipnum); GeoIPRegion_delete(region); } } else if (GEOIP_CITY_EDITION_REV0 == i) { gir = GeoIP_record_by_ipnum(gi, ipnum); if (NULL == gir) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s, %s, %s, %s, %f, %f\n", GeoIPDBDescription[i], gir->country_code, _mk_NA(gir->region), _mk_NA(gir->city), _mk_NA(gir->postal_code), gir->latitude, gir->longitude); _say_range_by_ip(gi, ipnum); GeoIPRecord_delete(gir); } } else if (GEOIP_CITY_EDITION_REV1 == i) { gir = GeoIP_record_by_ipnum(gi, ipnum); if (NULL == gir) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s, %s, %s, %s, %f, %f, %d, %d\n", GeoIPDBDescription[i], gir->country_code, _mk_NA(gir->region), _mk_NA(gir->city), _mk_NA(gir->postal_code), gir->latitude, gir->longitude, gir->metro_code, gir->area_code); _say_range_by_ip(gi, ipnum); GeoIPRecord_delete(gir); } } else if (GEOIP_CITYCONFIDENCE_EDITION == i) { gir = GeoIP_record_by_ipnum(gi, ipnum); if (NULL == gir) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { char country_str[5], region_str[5], city_str[5], postal_str[5]; _mk_conf_str(gir->country_conf, country_str, 5); _mk_conf_str(gir->region_conf, region_str, 5); _mk_conf_str(gir->city_conf, city_str, 5); _mk_conf_str(gir->postal_conf, postal_str, 5); printf("%s: %s, %s, %s, %s, %f, %f, %d, %d, %s, %s, %s, %s\n", GeoIPDBDescription[i], gir->country_code, _mk_NA(gir->region), _mk_NA(gir->city), _mk_NA(gir->postal_code), gir->latitude, gir->longitude, gir->metro_code, gir->area_code, country_str, region_str, city_str, postal_str ); _say_range_by_ip(gi, ipnum); GeoIPRecord_delete(gir); } } else if (GEOIP_CITYCONFIDENCEDIST_EDITION == i) { gir = GeoIP_record_by_ipnum(gi, ipnum); if (NULL == gir) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { char country_str[5], region_str[5], city_str[5], postal_str[5], accuracy_radius_str[5]; _mk_conf_str(gir->country_conf, country_str, 5); _mk_conf_str(gir->region_conf, region_str, 5); _mk_conf_str(gir->city_conf, city_str, 5); _mk_conf_str(gir->postal_conf, postal_str, 5); if (gir->accuracy_radius != 1023){ sprintf(accuracy_radius_str, "%d", gir->accuracy_radius ); } else { strcpy(accuracy_radius_str,"N/A");} printf("%s: %s, %s, %s, %s, %f, %f, %d, %d, %s, %s, %s, %s, %s\n", GeoIPDBDescription[i], gir->country_code, _mk_NA(gir->region), _mk_NA(gir->city), _mk_NA(gir->postal_code), gir->latitude, gir->longitude, gir->metro_code, gir->area_code, country_str, region_str, city_str, postal_str, accuracy_radius_str ); _say_range_by_ip(gi, ipnum); GeoIPRecord_delete(gir); } } else if (GEOIP_ORG_EDITION == i || GEOIP_ISP_EDITION == i) { org = GeoIP_org_by_ipnum(gi, ipnum); if (org == NULL) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s\n", GeoIPDBDescription[i], org); _say_range_by_ip(gi, ipnum); } } else if (GEOIP_NETSPEED_EDITION == i) { netspeed = GeoIP_id_by_ipnum(gi, ipnum); if (netspeed == GEOIP_UNKNOWN_SPEED) { printf("%s: Unknown\n", GeoIPDBDescription[i]); } else if (netspeed == GEOIP_DIALUP_SPEED) { printf("%s: Dialup\n", GeoIPDBDescription[i]); } else if (netspeed == GEOIP_CABLEDSL_SPEED) { printf("%s: Cable/DSL\n", GeoIPDBDescription[i]); } else if (netspeed == GEOIP_CORPORATE_SPEED) { printf("%s: Corporate\n", GeoIPDBDescription[i]); } _say_range_by_ip(gi, ipnum); } else { /* * Silent ignore IPv6 databases. Otherwise we get annoying * messages whenever we have a mixed environment IPv4 and * IPv6 */ /* * printf("Can not handle database type -- try geoiplookup6\n"); */ ; } } }
int main() { GeoIP *gi; GeoIPRegion *gir, giRegion; FILE *f; char ipAddress[30]; char expectedCountry[3]; char expectedCountry3[4]; const char *time_zone; gi = GeoIP_open("../data/GeoIPRegion.dat", GEOIP_MEMORY_CACHE); if (gi == NULL) { fprintf(stderr, "Error opening database\n"); exit(1); } f = fopen("region_test.txt", "r"); if (f == NULL) { fprintf(stderr, "Error opening region_test.txt\n"); exit(1); } gir = GeoIP_region_by_addr(gi, "10.0.0.0"); if (gir != NULL) { printf("lookup of private IP address: country = %s, region = %s\n", gir->country_code, gir->region); } while (fscanf(f, "%s%s%s", ipAddress, expectedCountry, expectedCountry3) != EOF) { printf("ip = %s\n", ipAddress); gir = GeoIP_region_by_name(gi, ipAddress); if (gir != NULL) { time_zone = GeoIP_time_zone_by_country_and_region(gir->country_code, gir->region); printf("%s, %s, %s, %s\n", gir->country_code, (!gir->region[0]) ? "N/A" : gir->region, _mk_NA(GeoIP_region_name_by_code (gir->country_code, gir->region)), _mk_NA(time_zone)); } else { printf("NULL!\n"); } GeoIP_assign_region_by_inetaddr(gi, inetaddr(ipAddress), &giRegion); if (gir != NULL) { assert(giRegion.country_code[0]); assert(!strcmp(gir->country_code, giRegion.country_code)); if (gir->region[0]) { assert(giRegion.region[0]); assert(!strcmp(gir->region, giRegion.region)); } else { assert(!giRegion.region[0]); } } else { assert(!giRegion.country_code[0]); } if (gir != NULL) { GeoIPRegion_delete(gir); } } GeoIP_delete(gi); fclose(f); return 0; }
void geoiplookup(GeoIP * gi, char *hostname, int i) { const char *country_code; const char *country_name; const char *domain_name; int netspeed; int country_id; GeoIPRegion *region; GeoIPRecord *gir; const char *org; uint32_t ipnum; ipnum = _GeoIP_lookupaddress(hostname); if (ipnum == 0) { printf("%s: can't resolve hostname ( %s )\n", GeoIPDBDescription[i], hostname); } else { if (GEOIP_DOMAIN_EDITION == i) { domain_name = GeoIP_name_by_ipnum(gi, ipnum); if (domain_name == NULL) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s\n", GeoIPDBDescription[i], domain_name); } } else if (GEOIP_COUNTRY_EDITION == i) { country_id = GeoIP_id_by_ipnum(gi, ipnum); country_code = GeoIP_country_code[country_id]; country_name = GeoIP_country_name[country_id]; if (country_id == 0) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s, %s\n", GeoIPDBDescription[i], country_code, country_name); } } else if (GEOIP_REGION_EDITION_REV0 == i || GEOIP_REGION_EDITION_REV1 == i) { region = GeoIP_region_by_ipnum(gi, ipnum); if (NULL == region) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s, %s\n", GeoIPDBDescription[i], region->country_code, region->region); GeoIPRegion_delete(region); } } else if (GEOIP_CITY_EDITION_REV0 == i) { gir = GeoIP_record_by_ipnum(gi, ipnum); if (NULL == gir) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s, %s, %s, %s, %f, %f\n", GeoIPDBDescription[i], gir->country_code, _mk_NA(gir->region), _mk_NA(gir->city), _mk_NA(gir->postal_code), gir->latitude, gir->longitude); } } else if (GEOIP_CITY_EDITION_REV1 == i) { gir = GeoIP_record_by_ipnum(gi, ipnum); if (NULL == gir) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s, %s, %s, %s, %f, %f, %d, %d\n", GeoIPDBDescription[i], gir->country_code, _mk_NA(gir->region), _mk_NA(gir->city), _mk_NA(gir->postal_code), gir->latitude, gir->longitude, gir->metro_code, gir->area_code); } } else if (GEOIP_ORG_EDITION == i || GEOIP_ISP_EDITION == i) { org = GeoIP_org_by_ipnum(gi, ipnum); if (org == NULL) { printf("%s: IP Address not found\n", GeoIPDBDescription[i]); } else { printf("%s: %s\n", GeoIPDBDescription[i], org); } } else if (GEOIP_NETSPEED_EDITION == i) { netspeed = GeoIP_id_by_ipnum(gi, ipnum); if (netspeed == GEOIP_UNKNOWN_SPEED) { printf("%s: Unknown\n", GeoIPDBDescription[i]); } else if (netspeed == GEOIP_DIALUP_SPEED) { printf("%s: Dialup\n", GeoIPDBDescription[i]); } else if (netspeed == GEOIP_CABLEDSL_SPEED) { printf("%s: Cable/DSL\n", GeoIPDBDescription[i]); } else if (netspeed == GEOIP_CORPORATE_SPEED) { printf("%s: Corporate\n", GeoIPDBDescription[i]); } } else { /* * Silent ignore IPv6 databases. Otherwise we get annoying * messages whenever we have a mixed environment IPv4 and * IPv6 */ /* * printf("Can not handle database type -- try geoiplookup6\n"); */ ; } } }