### ASP City/ISP/Org Web Service Integration Source: https://dev.maxmind.com/geoip/docs/web-services/legacy This ASP example shows how to make an HTTP GET request to the MaxMind City/ISP/Org web service using Msxml2.ServerXMLHTTP. Replace 'license_key' and 'ipaddress' with your actual values. ```ASP Dim objHttp, strQuery strQuery = "https://geoip.maxmind.com/v1.0/city-isp-org?l=" & license_key & "&i=" & ipaddress set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP") objHttp.open "GET", strQuery, false objHttp.send Response.Write objHttp.ResponseText Set objHttp = Nothing ``` -------------------------------- ### VBScript City/ISP/Org Web Service Integration Source: https://dev.maxmind.com/geoip/docs/web-services/legacy This VBScript example demonstrates fetching GeoIP data by making a GET request to the MaxMind City/ISP/Org web service and then splitting the comma-delimited response into individual variables. Ensure 'license_key' and 'ip_address' are correctly set. ```VBScript Set request = Server.CreateObject("AspHTTP.Conn") request.Url = "https://geoip.maxmind.com/v1.0/city-isp-org?l=" & license_key & "&i=" & ip_address request.RequestMethod = "GET" string = request.GetURL data = Split(string, ",") country = arr(0) region = arr(1) city = arr(2) postal = arr(3) latitude = arr(4) longitude = arr(5) metro_code = arr(6) area_code = arr(7) isp = arr(8) organization = arr(9) error = arr(10) ``` -------------------------------- ### Downloading Example CSV File Source: https://dev.maxmind.com/geoip/docs/databases/static-ip-score Example of a zip file name for the GeoIP Static IP Score CSV database. The actual file name will include a date. ```text GeoIP2-Static-IP-Score-CSV_Example.zip ``` -------------------------------- ### Downloading Example MMDB File Source: https://dev.maxmind.com/geoip/docs/databases/static-ip-score Example of a test MMDB file name for the GeoIP Static IP Score database. These files are available on GitHub. ```text GeoIP2-Static-IP-Score-Test.mmdb ``` -------------------------------- ### Locate GeoIP Update Installation Source: https://dev.maxmind.com/geoip/upgrading-geoip-update Determine the installation path of the geoipupdate executable. This is important when upgrading to avoid conflicting versions, especially if installed via 'make install'. ```bash which geoipupdate ``` ```text /usr/bin/geoipupdate ``` -------------------------------- ### Test GeoIP Update with Verbose Mode Source: https://dev.maxmind.com/geoip/upgrading-geoip-update Run geoipupdate in verbose mode after installation to confirm it is using the expected configuration file and completing successfully. This is crucial for verifying the upgrade. ```bash geoipupdate -v ``` ```text Using config file /etc/GeoIP.conf ... ``` -------------------------------- ### Cold Fusion City/ISP/Org Web Service Integration Source: https://dev.maxmind.com/geoip/docs/web-services/legacy This Cold Fusion example demonstrates how to call the City/ISP/Org web service, parse the comma-separated response, and store it in structures for easy access by ID and name. Ensure you replace 'LicenceKey' with your actual MaxMind license key. ```Cold Fusion
#qMaxMindByID[3]#
#qMaxMindByName['city']#

``` -------------------------------- ### Check GeoIP Update Version Source: https://dev.maxmind.com/geoip/upgrading-geoip-update Run this command to check your current installed version of GeoIP Update. This helps determine if an upgrade is necessary. ```bash geoipupdate -V ``` ```text geoipupdate 3.1.1 ``` -------------------------------- ### Inspect MMDB with mmdbinspect tool Source: https://dev.maxmind.com/geoip/docs/databases/isp Use the mmdbinspect tool to query IP addresses from MMDB databases and get output in JSON format. This tool is built with Go. ```bash mmdbinspect --ip 8.8.8.8 --format json GeoIP2-ISP.mmdb ``` -------------------------------- ### Retrieve GeoLite Country Data for Your IP Source: https://dev.maxmind.com/geoip/docs/web-services Use this curl command to get GeoLite Country data for your IP address. Substitute your account ID and license key for the placeholders. ```bash curl -u "{account_id}:{license_key}" \ "https://geolite.info/geoip/v2.1/country/me?pretty" ``` -------------------------------- ### Example Traits Object Source: https://dev.maxmind.com/geoip/docs/web-services/responses This JSON object contains general traits associated with an IP address. It includes details like autonomous system information, connection type, domain, IP address, risk score, and anonymization flags. ```json { "autonomous_system_number": 1239, "autonomous_system_organization": "Linkem IR WiMax Network", "connection_type": "Cable/DSL", "domain": "example.com", "ip_address": "1.2.3.4", "ip_risk_snapshot": 45.5, "is_anonymous": true, "is_anonymous_vpn": true, "is_anycast": true, "is_hosting_provider": true, "is_public_proxy": true, "is_residential_proxy": true, "is_tor_exit_node": true, "isp": "Linkem spa", "mobile_country_code": "310", "mobile_network_code": "004", "organization": "Linkem IR WiMax Network", "network": "1.2.3.0/24", "static_ip_score": 1.5, "user_count": 1, "user_type": "traveler" } ``` -------------------------------- ### Crontab Entry for GeoIP Update Source: https://dev.maxmind.com/geoip/updating-databases Example of a crontab entry to automate the GeoIP Update program. This configuration runs the update twice a week and sends results to the specified email address. Ensure the path to geoipupdate is correct for your system. ```bash 1# top of crontab 2MAILTO=your@email.com 3 417 8 * * 0,3 /usr/local/bin/geoipupdate 5# end of crontab ``` -------------------------------- ### Automate GeoIP Database Download with wget Source: https://dev.maxmind.com/geoip/updating-databases Use wget to download a GeoIP database, including authentication with your account ID and license key. This command is suitable for scripting and ensures the correct file is saved. ```bash wget --content-disposition --user=YOUR_ACCOUNT_ID --password=YOUR_LICENSE_KEY 'https://download.maxmind.com/geoip/databases/GeoIP2-City-CSV/download?suffix=zip' ``` -------------------------------- ### GeoIP.conf Configuration File Source: https://dev.maxmind.com/geoip/updating-databases This is a template for the GeoIP.conf file used by the geoipupdate program. Replace placeholders with your account ID, license key, and edition IDs. For versions older than 2.5.0, use 'UserId' and 'ProductIds'. ```bash 1# GeoIP.conf file - used by geoipupdate program to update databases 2# from https://www.maxmind.com 3AccountID YOUR_ACCOUNT_ID_HERE 4LicenseKey YOUR_LICENSE_KEY_HERE 5EditionIDs YOUR_EDITION_IDS_HERE ``` -------------------------------- ### Download GeoIP Database with wget Source: https://dev.maxmind.com/geoip/track-location-name-updates This wget command facilitates GeoIP database downloads. Provide your account ID and license key for authentication. The command options ensure the file is downloaded correctly with its original filename. ```bash wget --content-disposition --user=YOUR_ACCOUNT_ID --password=YOUR_LICENSE_KEY 'https://download.maxmind.com/geoip/databases/GeoIP2-City/download?suffix=csv&artifact_type=Locations-Diff-Report' ``` -------------------------------- ### Inspect MMDB Files with mmdbinspect Source: https://dev.maxmind.com/geoip/docs/databases/user-count Use the mmdbinspect tool to query MaxMind DB files and get output in JSON format. This tool is useful for examining the contents of binary databases. ```bash mmdbinspect --file GeoIP2-User-Count.mmdb --ip 1.1.1.1 ``` -------------------------------- ### Automate GeoIP Exchange Report Download with wget Source: https://dev.maxmind.com/geoip/geoip-exchange Use this wget command to download the geofeed report. The report will be saved to a file named after the report ID (e.g., YOUR_REPORT_ID.csv). Provide your account ID and license key using the --user and --password options. ```bash wget --user=YOUR_ACCOUNT_ID --password=YOUR_LICENSE_KEY 'https://download.maxmind.com/geofeed/reports/v1.0/YOUR_GEOFEED_ID/YOUR_REPORT_ID' ``` -------------------------------- ### Using mmdbinspect to Query IPs Source: https://dev.maxmind.com/geoip/docs/databases/static-ip-score Use the mmdbinspect tool to query IP addresses from MMDB databases and get output in JSON format. This tool is useful for inspecting binary database contents. ```bash mmdbinspect --ip 8.8.8.8 --db GeoIP2-Static-IP-Score.mmdb ``` -------------------------------- ### Perl Client for MaxMind Insights Web Service Source: https://dev.maxmind.com/geoip/docs/web-services/legacy This Perl script demonstrates how to query the MaxMind Insights web service. It requires the LWP::UserAgent, Text::CSV_XS, and URI modules. Ensure you replace 'YOUR_LICENSE_KEY' with your actual license key. ```Perl 1#!/usr/bin/env perl 2 3use strict; 4use warnings; 6use Encode qw( decode ); 7use Getopt::Long; 8use LWP::UserAgent; 9use Text::CSV_XS; 10use URI; 11use URI::QueryParam; 13my @fields = qw( 14 country_code 15 country_name 16 region_code 17 region_name 18 city_name 19 latitude 20 longitude 21 metro_code 22 area_code 23 time_zone 24 continent_code 25 postal_code 26 isp_name 27 organization_name 28 domain 29 as_number 30 netspeed 31 user_type 32 accuracy_radius 33 country_confidence 34 city_confidence 35 region_confidence 36 postal_confidence 37 error 38); 39my $license_key = 'YOUR_LICENSE_KEY'; 40my $ip_address = '24.24.24.24'; 43GetOptions( 44 'license:s' => \$license_key, 45 'ip:s' => \$ip_address, 46); 47my $uri = URI->new('https://geoip.maxmind.com/v1.0/insights'); 48$uri->query_param( l => $license_key ); 49$uri->query_param( i => $ip_address ); 50my $ua = LWP::UserAgent->new( timeout => 5 ); 51my $response = $ua->get($uri); 52die 'Request failed with status ' . $response->code() 53 unless $response->is_success(); 54my $csv = Text::CSV_XS->new( { binary => 1 } ); 55$csv->parse( decode( 'ISO-8859-1', $response->content() ) ); 56my %insights; 57@insights{@fields} = $csv->fields(); 58binmode STDOUT, ':encoding(UTF-8)'; 59if ( defined $insights{error} && length $insights{error} ) { 60 die "MaxMind returned an error code for the request: $insights{error}\n"; 61} 62else { 63 print "\nMaxMind Insights data for $ip_address\n\n"; 64 for my $field (@fields) { 65 print sprintf( " %-20s %s\n", $field, $insights{$field} ); 66 } 67 print "\n"; 68} ``` -------------------------------- ### GeoIP Insights Response Example Source: https://dev.maxmind.com/geoip/docs/web-services/responses This JSON object represents a complete response from the GeoIP Insights web service, detailing geographical information, network traits, and anonymization status for an IP address. ```json { "continent": { "code": "NA", "geoname_id": 123456, "names": { "de": "Nordamerika", "en": "North America", "es": "América del Norte", "fr": "Amérique du Nord", "ja": "北アメリカ", "pt-BR": "América do Norte", "ru": "Северная Америка", "zh-CN": "北美洲" } }, "country": { "geoname_id": 6252001, "is_in_european_union": false, "iso_code": "US", "names": { "de": "USA", "en": "United States", "es": "Estados Unidos", "fr": "États-Unis", "ja": "アメリカ合衆国", "pt-BR": "Estados Unidos", "ru": "США", "zh-CN": "美国" }, "confidence": 75 }, "maxmind": { "queries_remaining": 54321 }, "registered_country": { "geoname_id": 6252001, "is_in_european_union": true, "iso_code": "US", "names": { "de": "USA", "en": "United States", "es": "Estados Unidos", "fr": "États-Unis", "ja": "アメリカ合衆国", "pt-BR": "Estados Unidos", "ru": "США", "zh-CN": "美国" } }, "represented_country": { "geoname_id": 6252001, "is_in_european_union": true, "iso_code": "US", "names": { "de": "USA", "en": "United States", "es": "Estados Unidos", "fr": "États-Unis", "ja": "アメリカ合衆国", "pt-BR": "Estados Unidos", "ru": "США", "zh-CN": "美国" }, "type": "military" }, "anonymizer": { "confidence": 99, "is_anonymous": true, "is_anonymous_vpn": true, "is_hosting_provider": true, "is_public_proxy": true, "is_residential_proxy": true, "is_tor_exit_node": true, "network_last_seen": "2025-01-15", "provider_name": "nordvpn" }, "traits": { "ip_address": "1.2.3.4", "ip_risk_snapshot": 45.5, "is_anycast": true, "network": "1.2.3.0/24", "autonomous_system_number": 1239, "autonomous_system_organization": "Linkem IR WiMax Network", "connection_type": "Cable/DSL", "domain": "example.com", "isp": "Linkem spa", "mobile_country_code": "310", "mobile_network_code": "004", "organization": "Linkem IR WiMax Network", "is_anonymous": true, "is_anonymous_vpn": true, "is_hosting_provider": true, "is_public_proxy": true, "is_residential_proxy": true, "is_tor_exit_node": true, "static_ip_score": 1.5, "user_count": 1, "user_type": "traveler" }, "city": { "confidence": 25, "geoname_id": 54321, "names": { "de": "Los Angeles", "en": "Los Angeles", "es": "Los Ángeles", "fr": "Los Angeles", "ja": "ロサンゼルス市", "pt-BR": "Los Angeles", "ru": "Лос-Анджелес", "zh-CN": "洛杉矶" } }, "location": { "accuracy_radius": 20, "latitude": 37.6293, "longitude": -122.1163, "metro_code": 807, "time_zone": "America/Los_Angeles", "average_income": 128321, "population_density": 1234 }, "postal": { "code": "90001", "confidence": 10 }, "subdivisions": [ { "geoname_id": 5332921, "iso_code": "CA", "names": { "de": "Kalifornien", "en": "California", "es": "California", "fr": "Californie", "ja": "カリフォルニア", "ru": "Калифорния", "zh-CN": "加州" }, "confidence": 50 } ] } ``` -------------------------------- ### Download GeoIP Database with curl Source: https://dev.maxmind.com/geoip/track-location-name-updates Use this curl command to download GeoIP databases. Ensure you replace YOUR_ACCOUNT_ID and YOUR_LICENSE_KEY with your actual credentials. The URL includes parameters for specifying the database type and format. ```bash curl -O -J -L -u YOUR_ACCOUNT_ID:YOUR_LICENSE_KEY 'https://download.maxmind.com/geoip/databases/GeoIP2-City/download?suffix=csv&artifact_type=Locations-Diff-Report' ``` -------------------------------- ### GeoIP Legacy Web Services - City Lookup Source: https://dev.maxmind.com/geoip/docs/web-services/legacy This service provides city-level geolocation data for a given IP address. It accepts the IP address and license key as parameters via GET or POST. ```APIDOC ## GET /geoip/v1.0/city ### Description Retrieves city-level geolocation information for a specified IP address. ### Method GET ### Endpoint `https://geoip.maxmind.com/geoip/v1.0/city` ### Parameters #### Query Parameters - **i** (string) - Required - The IP address to look up (e.g., "44.55.66.77" or "2001:db8::2:1"). - **l** (string) - Required - Your MaxMind license key. ### Request Example `https://geoip.maxmind.com/geoip/v1.0/city?i=44.55.66.77&l=YOUR_LICENSE_KEY` ### Response #### Success Response (200) - **City data** (string) - The geolocation data for the IP address in plain text format. #### Response Example ``` US, MA, Boston, 02110 ``` ``` -------------------------------- ### GeoIP Legacy Web Services - Country Lookup Source: https://dev.maxmind.com/geoip/docs/web-services/legacy This service provides country-level geolocation data for a given IP address. It accepts the IP address and license key as parameters via GET or POST. ```APIDOC ## GET /geoip/v1.0/country ### Description Retrieves country-level geolocation information for a specified IP address. ### Method GET ### Endpoint `https://geoip.maxmind.com/geoip/v1.0/country` ### Parameters #### Query Parameters - **i** (string) - Required - The IP address to look up (e.g., "44.55.66.77" or "2001:db8::2:1"). - **l** (string) - Required - Your MaxMind license key. ### Request Example `https://geoip.maxmind.com/geoip/v1.0/country?i=44.55.66.77&l=YOUR_LICENSE_KEY` ### Response #### Success Response (200) - **Country data** (string) - The geolocation data for the IP address in plain text format. #### Response Example ``` US ``` ``` -------------------------------- ### Check Latest GeoIP Exchange Report Release Date with wget Source: https://dev.maxmind.com/geoip/geoip-exchange Use this wget command to issue a HEAD request and check the `Last-Modified` header for the geofeed report's build date. Provide your account ID and license key using the --user and --password options. ```bash wget -S \ --method HEAD \ --user=YOUR_ACCOUNT_ID \ --password=YOUR_LICENSE_KEY \ 'https://download.maxmind.com/geofeed/reports/v1.0/YOUR_GEOFEED_ID/YOUR_REPORT_ID' ``` -------------------------------- ### Example GeoIP JSON Response Structure Source: https://dev.maxmind.com/geoip/docs/web-services/responses This illustrates a typical top-level JSON object returned by GeoIP services. The exact keys present will differ based on the service queried (e.g., Country, City Plus, Insights). ```json { "anonymizer": { ... }, "city": { ... }, "continent": { ... }, "country": { ... }, "location": { ... }, "postal": { ... }, "registered_country": { ... }, "represented_country": { ... }, "subdivisions": [{ ... }, ... ], "traits": { ... }, "maxmind": { ... } } ``` -------------------------------- ### Automate GeoIP Database Download with curl Source: https://dev.maxmind.com/geoip/updating-databases Download a GeoIP database using curl by providing your account ID and license key for authentication. This command follows redirects and saves the file. ```bash curl -O -J -L -u YOUR_ACCOUNT_ID:YOUR_LICENSE_KEY 'https://download.maxmind.com/geoip/databases/GeoIP2-City-CSV/download?suffix=zip' ``` -------------------------------- ### Anonymizer JSON Object Example Source: https://dev.maxmind.com/geoip/docs/web-services/responses This JSON object indicates whether an IP address belongs to an anonymizing service. It includes confidence scores and boolean flags for various anonymization types. This data is available for GeoIP Insights only. ```json { "confidence": 99, "is_anonymous": true, "is_anonymous_vpn": true, "is_hosting_provider": true, "is_public_proxy": true, "is_residential_proxy": true, "is_tor_exit_node": true, "network_last_seen": "2025-01-15", "provider_name": "nordvpn" } ``` -------------------------------- ### Ruby 1.9: Query MaxMind GeoIP Insights Source: https://dev.maxmind.com/geoip/docs/web-services/legacy This Ruby script interacts with the MaxMind Insights web service. It requires the 'csv', 'net/http', 'open-uri', 'optparse', and 'uri' libraries. Remember to replace 'YOUR_LICENSE_KEY' with your actual license key. ```Ruby #!/usr/bin/env ruby require 'csv' require 'net/http' require 'open-uri' require 'optparse' require 'uri' fields = [:country_code, :country_name, :region_code, :region_name, :city_name, :latitude, :longitude, :metro_code, :area_code, :time_zone, :continent_code, :postal_code, :isp_name, :organization_name, :domain, :as_number, :netspeed, :user_type, :accuracy_radius, :country_confidence, :city_confidence, :region_confidence, :postal_confidence, :error] options = { :license => "YOUR_LICENSE_KEY", :ip => "24.24.24.24" } OptionParser.new { |opts| opts.banner = "Usage: insights-geoip-ws.rb [options]" opts.on("-l", "--license LICENSE", "MaxMind license key") do |l| options[:license] = l end opts.on("-i", "--ip IPADDRESS", "IP address to look up") do |i| options[:ip] = i end }.parse! uri = URI::HTTP.build(:scheme => 'https', :host => 'geoip.maxmind.com', :path => '/v1.0/insights', :query => URI.encode_www_form(:l => options[:license], :i => options[:ip])) response = Net::HTTP.get_response(uri) unless response.is_a?(Net::HTTPSuccess) abort "Request failed with status #{response.code}" end insights = Hash[fields.zip(response.body.encode('utf-8', 'iso-8859-1').parse_csv)] if insights[:error] abort "MaxMind returned an error code for the request: #{insights[:error]}" else puts puts "MaxMind Insights data for #{options[:ip]}"; puts insights.each { |key, val| printf " %-20s %s\n", key, val } puts end ```