EzDevInfo.com

geoip

The Ruby gem for querying Maxmind.com's GeoIP database, which returns the geographic location of a server given its IP address geoip

Geo Location based on IP Address - PHP [closed]

We're looking for a fast and accurate way to get the visitors location based on their IP.

We have tried ipinfodb.com but their API made our website severely lag when making the API call.

What other services do you suggest?


Source: (StackOverflow)

PHP Regex for IP to Location API

How would I use Regex to get the information on a IP to Location API

This is the API

http://ipinfodb.com/ip_query.php?ip=74.125.45.100

I would need to get the Country Name, Region/State, and City.

I tried this:

$ip = $_SERVER["REMOTE_ADDR"];
$contents = @file_get_contents('http://ipinfodb.com/ip_query.php?ip=' . $ip . '');
$pattern = "/<CountryName>(.*)<CountryName>/";
preg_match($pattern, $contents, $regex);
$regex = !empty($regex[1]) ? $regex[1] : "FAIL";
echo $regex;

When I do echo $regex I always get FAIL how can I fix this


Source: (StackOverflow)

Advertisements

Get Country of IP Address with PHP

Ideally I'm trying to put together a PHP script that I can query from any web browser and it returns the Country of the IP address that accessed the PHP script.

Is this possible or is there a better solution?


Source: (StackOverflow)

GeoIP database/API providers other than MaxMind

I'm looking for GeoIP database/API providers. I need a local database with C# API with country level accuracy (for now). So far the only one that I find is MaxMind.

Not that there's anything wrong with MaxMind and their price for what I need is reasonable, but I'd like to evaluate alternatives before committing.

Did I miss any other similar offerings?


Source: (StackOverflow)

what maxmind geoip ruby wrapper is up2date and usable? ( for the commercial library )

Im trying to get below github repo in my app

https://github.com/mtodd/geoip

Ive tried adding it like

gem "geoip", :git => "git://github.com/mtodd/geoip.git"

Error =

Could not find gem 'geoip (>= 0) ruby' in git://github.com/mtodd/geoip.git (at master).
Source does not contain any versions of 'geoip (>= 0) ruby'

Is there are ruby gem wrapper for GeoIP that is compatible with the LATEST GEOIP? Ive searched very long for one, the one above seems to be sort off compatible with 1.4.7 and higher but I can't get it installed, any other suggestion? Thx !


Source: (StackOverflow)

Installing C library in Heroku

I'm trying to use GeoIP with Django. It requires the MaxMind GeoIP C API.

If I were using Ruby, I could simply use the 'geoip' gem which bundles the C API and the Ruby bindings, as explained in Installing MaxMind GeoIP ruby library on heroku.

Unfortunately, nothing like this exists for Python, so I'm wondering how I would go about installing the C API from source on Heroku, or if there's the equivalent of a package manager on Heroku (ie. 'brew install geoip' for OS X, and 'sudo apt-get install geoip' for Ubuntu).


Source: (StackOverflow)

Error setting up geoip on Django

I'm trying to add geolocation to a website, using GeoIP. I followed the instructions on Django docs, but I get this error: ImproperlyConfigured: Error importing middleware middleware: "cannot import name GeoIP" What can be missing? I've added the geolocation function as a custom middleware as below:

from django.contrib.gis.utils import GeoIP

class LocationMiddleware(object):
    def process_request(self, request):
        g = GeoIP()
        ip = request.META.get('REMOTE_ADDR', None)
        if (not ip or ip == '127.0.0.1') and 
          request.META.has_key('HTTP_X_FORWARDED_FOR'):
            ip = request.META['HTTP_X_FORWARDED_FOR']
        if ip:
           city = g.city(ip)['city']
        else:
           # set default city

    return city

Source: (StackOverflow)

Only allow certain countries traffic access specific page

I am using --with-http_geoip_module for identify traffic. There are some pages that I only want certain country to access. Here is configuration:

For http

 http{
    geoip_country  /usr/share/GeoIP/GeoIP.dat; # the country IP database
    map $geoip_country_code $allowed_country {
            default 0;
            US 1;
            UK 1;
            HK 1; 

     }

  }

The location directive:

location = /testing {
            if ($allowed_country = 0) {

                    return 301 ;
              }
    }

The problem is when I using US/HK IPs, I get a 404 error. What did I done wrong?

UPDATE

Here is my complete conf file:

http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

geoip_country  /usr/share/GeoIP/GeoIP.dat; # the country IP database

map $geoip_country_code $allowed_country {
        default 0;
        US 1;
        UK 1;
        HK 1; 

 }
sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

index   index.html index.htm;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
    listen       80 default_server;
    server_name  localhost;
    root         /var/www/html;

    include /etc/nginx/default.d/*.conf;

    location / {
        index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
        try_files $uri $uri/ /index.php?$args;
    }

    # redirect server error pages to the static page /40x.html
    #
    error_page  404              /404.html;
    location = /40x.html {
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    }

    #ban specifc country
    location = /testing {
        if ($allowed_country = 0) {

                return 301 ;
          }
     }


    location ~ \.php$ {
        ### SET GEOIP Variables ###
        fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
        fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
        fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;

        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
        return 404;

        }
            try_files $uri $uri/ /index.php?$args;
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi.conf;
            include conf/site.conf;
    } 

}
 }

Basically I want only visitor from US, UK and HK access /testing page.


Source: (StackOverflow)

geoIP find country from ASP.NET

From an ASP.NET page I'm able to retrieve the client's IP address (at least the apparent one).

I would like to know if there is a free service that I can access from code-behind, that will return the country (no need for city) when queried with the IP.

I can't make do with web http based services where you have to enter the IP manually, I have thousands of visits per day!

Any clue welcome.


Source: (StackOverflow)

Apache 2.4 require not ip range not working (blacklist ignored when GEOIP active)

I'm trying to understand what's going on. If i add a single IP to my blacklist using

Require not ip xxx.xxx.xxx.xxx

It just works, Apache 2.4 throws a 403. Now i've tried to use the whole range and it still let the request go through. I used:

Require not ip xxx.xxx.xxx.1 xxx.xxx.xxx.255

Apache 2.4 returns 200 instead of 403. What am i doing wrong?

Thanks

Edit: Here's a simple test case from my local network.

Require not ip 192.168.1.180/192.168.1.185

Used computer on ip 192.168.1.183, and wasn't blocked at all.

Here's my httpd.conf and the ips are in a seperate blacklist.txt. Also it works with a single ip, the issue is only related to a RANGE of IPs.

    <Directory "f:/root">  
    Options Indexes FollowSymLinks  
    AllowOverride All   
    <LimitExcept GET POST HEAD>  
    </LimitExcept>
    <RequireAll>
      Require all granted
      Include conf/blacklist.txt
   </RequireAll>   
   </Directory>

Edit2: Did another test and it seems that the issue comes from using a blacklist + GEOIP. Blacklist alone works with xxx.xxx.xxx.0/xxx.xxx.xxx.255 but as soon as mod_geoip is active, the blacklist is ignored.

Here is my GEOIP config:

<IfModule geoip_module>
    GeoIPEnable On
    GeoIPEnableUTF8 On
    GeoIPOutput Env
    GeoIPScanProxyHeaders On
    GeoIPDBFile bin/GeoIP.dat MemoryCache
    SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
</IfModule>

If there a way to have BOTH blacklist and GEOIP working together??


Source: (StackOverflow)

GeoIP and IP to Country in PHP [duplicate]

Possible Duplicate:
How to get the page visitors Country with PHP?

I've been searching everywhere, and I can't seem to find anything. I need a free PHP GeoIP/Ip to country.

All I can find is that it gives me the country and small form of the country. I also would like to have information of possible street or coords, city, and maybe host information?

I need this because I am creating a PHP CMS (for myself and clients) and I want to track ips.

I don't really want an API, I want it like a database. Any ideas ?


Source: (StackOverflow)

How can I get the user's IP while using both CloudFlare and MaxMind's GeoIP with mod_geoip?

CloudFlare provides the user's country from the originating IP but I need location on a city level so I've added MaxMind's GeoCityLite using the mod_geoip Apache script.

The problem is now to get the IP in a php variable, I'm using something like

$country = apache_note("GEOIP_COUNTRY_CODE");

This is great but the IP mod_geoip is using is the CloudFlare DNS, not the end user. CloudFlare offers the server variable HTTP_CF_CONNECTING_IP to use the end-user IP but how do I use THAT variable/IP in the mod_geoip?

Can this be done with a few lines in htaccess?

Edit: I have a workaround using the php API for geoip which is easy but the benchmarks using the apache lookup of the php api is much much better so I'd rather find this solution.


Source: (StackOverflow)

Intermittent ImportError with Django package

I have the following import line in a Django 1.4 project running in Python 2.7.6:

from django.contrib.gis.utils import GeoIP

This line works just fine 100% of the time in production and in development, but this line fails with an ImportError in test--sometimes. Given the following dummy test:

from django.test import TestCase
from django.test.client import Client

class DummyTestCase(TestCase):
    def test_GET_200_response_code(self):
        c = Client()
        response = c.get('/')
        self.assertEqual(response.status_code, 200)

If I run only the tests in this module, it fails on the response = self.c.get('/') line:

...
File "...", line 19, in <module>  
    from django.contrib.gis.utils import GeoIP
ImportError: cannot import name GeoIP

However when I run the entire test suite, including this same test, it passes without problems. And, again, the import works fine in console, and in the server in dev and production.

So... why is that happening? Why would I get an ImportError only when running this single test module and never otherwise, even if I run all the tests including this module?

Note: I'm using Django 1.4 right now. I'm aware that the import path changes and will be from django.contrib.gis.geoip import GeoIP, but the shortcut from utils is still there in 1.4, until 1.6. Either way, switching the import path demonstrates the same behavior as described above.


Source: (StackOverflow)

How does the binary DAT from Maxmind work?

Maxmind offers a binary DAT file format for downloading their GeoIP database.

http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

Does anyone know how this has been packaged? Also, is there any kind of copy protection on the data?

I'd like to offer up a set of data in a similar way.

Anyone with any knowledge of this will receive my undying gratitude :-)


Source: (StackOverflow)

location detection in web browser

I am searching for a method to locate the user location while visiting my website, i have tried Maxmind but they seems to be inaccurate in the city level. the information i want is (Country, City, longitude, latitude) i want the country and the city to be very accurate if possible.

I have also used HTML5 but the problem that it asks my user to share location information which seems to me bad solution. (althougth i got very accurate results)

Any solutions?

Notice: i found google search got an accurate detection and without "ask for sharing my location", but i didn't find any api to use google service


Source: (StackOverflow)