Use geoip for user IP Analysis

Source: Internet
Author: User
Tags geoip geoip database ip country maxmind

The geoip database of maxmind can accurately obtain the user's geographic location information based on the user's IP address. Firefox uses it to calculate the region where the user is downloaded.

It mainly includes two data files stored in key-value mode, GEO country and geo ip. If you only focus on country information, you can use a much smaller GEO country database.

Both databases are divided into commercial and free versions, with an accuracy rate above 99.5%. For most applications, free versions are sufficient.

Geoip clients include the following languages:

  • C library
  • Perl Module
  • PHP Module
  • Apache module (mod_geoip)
  • Java class
  • Python class
  • C # class
  • Ruby Module
  • Ms com Object
  • VB. NET
  • Pascal
  • Javascript
  •  

    The following uses Perl as an example to describe how to use it.

    Download the geolitecountry or geolitecity data file (http://www.maxmind.com/app/geolitecountryor http://www.maxmind.com/app/geolitecity ). The file size of geolitecountry is about 1 m, while that of geolitecountry is about 43 m.

     

    The geoip module of Perl mainly consists of two GEO: IP and GEO: IP: pureperl. The previous one calls the C language implementation, which is more efficient than the previous pure Perl implementation module.

    The following code analyzes IP country information:

    Use GEO: IP; </P> <p> my $ gi = GEO: IP-> New (geoip_standard ); <br/> my $ Country = $ Gi-> country_code_by_addr ("24.24.24.24") | 'no record '; </P> <p> Print "country: $ country/N "; <br/>

    Output:

    Country: US

    The following code analyzes the details of an IP Address:

    Use GEO: IP; </P> <p> my $ gi = <br/> GEO :: IP-> open ("/usr/local/share/geoip/geolitecity. dat ", geoip_standard); </P> <p> my $ r = $ Gi-> record_by_name (" 134.153.33.202 ") | 'no record '; </P> <p> Print join ("--", <br/> $ R-> country_code, $ R-> country_code3, $ R-> region, $ R-> region_name, $ R-> city, <br/> $ R-> postal_code, $ R-> latitude, $ R-> longpolling); <br/>

    Output:

    CA--CAN--NL -- Newfoundland-Saint John's ---- 47.5500 --- 52.6667

    You can see that this user is from St. John's district in newfenghua, Canada.

    Based on the statistics of the number of users in batches, we can analyze the key user regions and marketing results as an example, from which we can see the changing trend of the number of foreign users.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.