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; }
ipdata_t *ipdata_lookup(const char *inaddr, db_t *dbp) { char *city, *region, *country, *asnum, *empty = "X"; city = region = country = asnum = empty; ipdata_t *ip = NULL; GeoIPRecord *grp = NULL; if(!inaddr) return NULL; ip = MALLOCORDIE(sizeof(ipdata_t), "ipdata_lookup()"); ip->latitude = 0.0; ip->longitude = 0.0; /* Query the city database, if we have it. */ if(dbp->citygp) { if(opts.family == AF_INET6) grp = GeoIP_record_by_name_v6(dbp->citygp, inaddr); else grp = GeoIP_record_by_name(dbp->citygp, inaddr); if(grp) { if(grp->city) city = grp->city; if(grp->region) region = grp->region; if(grp->country_code) country = grp->country_code; ip->latitude = grp->latitude; ip->longitude = grp->longitude; } } /* Query the asnum database, if we have it. */ if(dbp->asgp) { if(opts.family == AF_INET6) asnum = GeoIP_org_by_name_v6(dbp->asgp, inaddr); else asnum = GeoIP_org_by_name(dbp->asgp, inaddr); if(!asnum) asnum = empty; } /* Copy data into ipdata_t for great thread safety. */ ip->address = MALLOCORDIE(strlen(inaddr) + 1, "ipdata_lookup()"); strcpy(ip->address, inaddr); ip->city = MALLOCORDIE(strlen(city) + 1, "ipdata_lookup()"); strcpy(ip->city, city); ip->region = MALLOCORDIE(strlen(region) + 1, "ipdata_lookup()"); strcpy(ip->region, region); ip->country = MALLOCORDIE(strlen(country) + 1, "ipdata_lookup()"); strcpy(ip->country, country); ip->asnum = MALLOCORDIE(strlen(asnum) + 1, "ipdata_lookup()"); strcpy(ip->asnum, asnum); if(strcmp(asnum, empty)) free(asnum); if(grp) GeoIPRecord_delete(grp); return ip; }
Variant f_geoip_org_by_name(CStrRef hostname) { if (!is_db_avail(GEOIP_COUNTRY_EDITION)) return null_variant; char *org = GeoIP_org_by_name(s_geoip->gi[GEOIP_COUNTRY_EDITION], hostname); if (org == NULL) { raise_notice("Host %s not found", hostname.data()); return false; } return String(org, AttachString); }
static PyObject * GeoIP_org_by_name_Py(PyObject *self, PyObject *args) { char * name; char * org; PyObject * ret; GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self; if (!PyArg_ParseTuple(args, "s", &name)) { return NULL; } org = GeoIP_org_by_name(GeoIP->gi, name); ret = Py_BuildValue("s", org); free(org); return ret; }
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; }