Ejemplo n.º 1
0
wxString CslGeoIP::GetCountryNameByAddr(const char *host)
{
    CslGeoIP& self = GetInstance();

    if (!g_geoIP)
        return wxEmptyString;

    GeoIPRecord *r = NULL;
    const char *country = NULL;

    switch (self.m_type)
    {
        case GEOIP_COUNTRY:
            country = GeoIP_country_name_by_addr(g_geoIP, host);
            break;
        case GEOIP_CITY:
            if ((r = GeoIP_record_by_addr(g_geoIP, host)))
            {
                country = r->country_name;
                GeoIPRecord_delete(r);
            }
            break;
    }

    return country ? C2U(country) : wxString(wxEmptyString);
}
Ejemplo n.º 2
0
void AddTLDUser( const Client *u )
{
	const char *country_name;
	const char *country_code;
	TLD *t = NULL;

	if( !gi )
		return;
	country_code = GeoIP_country_code_by_addr( gi, u->hostip );
	if( country_code )
	{
		t = lnode_find( tldstatlist, country_code, FindTLD );
		if( !t )
		{
			country_name = GeoIP_country_name_by_addr( gi, u->hostip );
			t = ns_calloc( sizeof( TLD ) );
			strlcpy( t->tld, country_code, 5 );
			strlcpy( t->country, country_name, 32 );
			lnode_create_append( tldstatlist, t );
		}
	}
	else
	{
		t = lnode_find( tldstatlist, UNKNOWN_COUNTRY_CODE, FindTLD );
	}
	IncStatistic( &t->users );
}
Ejemplo n.º 3
0
static PyObject * GeoIP_country_name_by_addr_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_addr(GeoIP->gi, name);
  return Py_BuildValue("s", retval);
}
Ejemplo n.º 4
0
static cell_t sm_Geoip_Country(IPluginContext *pCtx, const cell_t *params)
{
	char *ip;
	const char *ccode;

	pCtx->LocalToString(params[1], &ip);
	StripPort(ip);

	ccode = GeoIP_country_name_by_addr(gi, ip);
	pCtx->StringToLocal(params[2], params[3], (ccode) ? ccode : "");

	return ccode ? 1 : 0;
}
Ejemplo n.º 5
0
void testgeoipcountry(int flags, const char *msg, int numlookups)
{
    const char *str = NULL;
    double t = 0;
    int i4 = 0;
    int i2 = 0;
    GeoIP *i = NULL;
    i = GeoIP_open("/usr/local/share/GeoIP/GeoIP.dat", flags);
    if (i == NULL) {
        printf("error: GeoIP.dat does not exist\n");
        return;
    }
    timerstart();
    for (i2 = 0; i2 < numlookups; i2++) {
        str = GeoIP_country_name_by_addr(i, ipstring[i4]);
        i4 = (i4 + 1) % numipstrings;
    }
    t = timerstop();
    printf("%s\n", msg);
    printf("%d lookups made in %f seconds \n", numlookups, t);
    GeoIP_delete(i);
}
Ejemplo n.º 6
0
const char *ip_to_country(const char *ip) {
    if(!geoip) return "Unknown";
    const char *_country = GeoIP_country_name_by_addr(geoip, ip);
    const char *country = _country ? _country : "Unknown";
    return country;
}