Пример #1
0
void
geoip_get_country (const char *ip, char *location)
{
  GeoIPRecord *rec = NULL;
  const char *country = NULL, *code = NULL, *addr = ip;
  int geoid = 0;

  /* Custom GeoIP database */
  if (conf.geoip_city_data != NULL && geo_location_data != NULL) {
    rec = GeoIP_record_by_name (geo_location_data, addr);
    if (rec) {
      code = rec->country_code;
      country = rec->country_name;
    }
  }
  /* Legacy GeoIP database */
  else if (geo_location_data != NULL) {
    geoid = GeoIP_id_by_name (geo_location_data, addr);
    country = GeoIP_country_name_by_name (geo_location_data, addr);
    code = GeoIP_code_by_id (geoid);
  }

  geoip_set_country (country, code, location);
  if (rec != NULL)
    GeoIPRecord_delete (rec);
}
Пример #2
0
static PyObject * GeoIP_country_name_by_name_Py(PyObject *self, PyObject *args) {
  char * name;
  const char * retval;
  GeoIP_GeoIPObject* GeoIP = (GeoIP_GeoIPObject*)self;
  if (!PyArg_ParseTuple(args, "s", &name)) {
    return NULL;
  }
  retval = GeoIP_country_name_by_name(GeoIP->gi, name);
  return Py_BuildValue("s", retval);
}
Пример #3
0
Variant f_geoip_country_name_by_name(CStrRef hostname) {
  if (!is_db_avail(GEOIP_COUNTRY_EDITION))
    return null_variant;

  const char *country_name = GeoIP_country_name_by_name(s_geoip->gi[GEOIP_COUNTRY_EDITION], hostname.data());
  if (country_name == NULL) {
    raise_notice("Host %s not found", hostname.data());
    return false;
  }

  return String(country_name, CopyString);
}
Пример #4
0
/* Get the country name by GeoIP location id.
 *
 * On error, NULL is returned
 * On success, the country name is returned */
static const char *
geoip_get_country_by_geoid (const char *addr, GTypeIP type_ip)
{
  const char *country = NULL;

  if (TYPE_IPV4 == type_ip)
    country = GeoIP_country_name_by_name (geo_location_data, addr);
  else if (TYPE_IPV6 == type_ip)
    country = GeoIP_country_name_by_name_v6 (geo_location_data, addr);

  return country;
}
Пример #5
0
char *
get_geoip_data (const char *data)
{
  const char *location = NULL;
  const char *addr = data;

  /* Geolocation data */
  if (geo_location_data != NULL)
    location = GeoIP_country_name_by_name (geo_location_data, addr);
  if (location == NULL)
    location = "Location Unknown";
  return (char *) location;
}
Пример #6
0
Файл: hash.c Проект: NX-Andro/x3
void
set_geoip_info(struct userNode *user)
{
    if(IsLocal(user))
        return;
/* Need the libs and the headers if this is going to compile properly */
#if defined(HAVE_LIBGEOIP)&&defined(HAVE_GEOIP_H)&&defined(HAVE_GEOIPCITY_H)
    GeoIPRecord * gir;
    const char *geoip_data_file = NULL;
    const char *geoip_city_file = NULL;

    geoip_data_file = conf_get_data("services/opserv/geoip_data_file", RECDB_QSTRING);
    geoip_city_file = conf_get_data("services/opserv/geoip_city_data_file", RECDB_QSTRING);

    if ((!geoip_data_file && !geoip_city_file))
        return; /* Admin doesnt want to use geoip functions */

    if (geoip_data_file && !gi)
        gi  = GeoIP_open(geoip_data_file, GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE);

    if (geoip_city_file && !cgi)
        cgi = GeoIP_open(geoip_city_file, GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE);

    if (cgi) {
        gir = GeoIP_record_by_name(cgi, user->hostname);
        if (gir) {
            user->country_name = strdup(gir->country_name ? gir->country_name : "");
            user->country_code = strdup(gir->country_code ? gir->country_code : "");
            user->city         = strdup(gir->city ? gir->city : "");
            user->region       = strdup(gir->region ? gir->region : "");
            user->postal_code  = strdup(gir->postal_code ? gir->postal_code : "");

            user->latitude  = gir->latitude ? gir->latitude : 0;
            user->longitude = gir->longitude ? gir->longitude : 0;
            user->dma_code  = gir->dma_code ? gir->dma_code : 0;
            user->area_code = gir->area_code ? gir->area_code : 0;

            GeoIPRecord_delete(gir);
        }

        return;
    } else if (gi) {
        const char *country = GeoIP_country_name_by_name(gi, user->hostname);
        user->country_name = strdup(country ? country : "");
        return;
    }

    return;
#endif
}
Пример #7
0
/* Geolocation data */
char *
get_geoip_data (const char *data)
{
   const char *location = NULL;

#ifdef HAVE_LIBGEOIP
   const char *addr = data;
   /* Geolocation data */
   GeoIP *gi;
   gi = GeoIP_new (GEOIP_STANDARD);
   if (gi != NULL)
      location = GeoIP_country_name_by_name (gi, addr);
   if (location == NULL)
      location = "Location Unknown";
   if (gi != NULL)
      GeoIP_delete (gi);
#endif
   return (char *) location;
}