Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) MaxMind IPv4 Geolocation LookupDemonstrates how to lookup Geolocation data for an IPv4 address using the MaxMind GeoIP2 Precision Web Service.
load ./chilkat.dll # This example requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set http [new_CkHttp] CkHttp_put_Login $http "MAXMIND_ACCOUNT_ID" CkHttp_put_Password $http "MAXMIND_LICENSE_KEY" CkHttp_put_Accept $http "application/json" # Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address) set jsonStr [CkHttp_quickGetStr $http "https://geoip.maxmind.com/geoip/v2.1/country/149.250.207.170"] if {[CkHttp_get_LastMethodSuccess $http] == 0} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http exit } set json [new_CkJsonObject] CkJsonObject_put_EmitCompact $json 0 set success [CkJsonObject_Load $json $jsonStr] puts [CkJsonObject_emit $json] # Sample output: # Use this online tool to generate parsing code from sample JSON: # Generate Parsing Code from JSON # { # "continent": { # "code": "EU", # "geoname_id": 6255148, # "names": { # "ja": "?????", # "pt-BR": "Europa", # "ru": "??????", # "zh-CN": "??", # "de": "Europa", # "en": "Europe", # "es": "Europa", # "fr": "Europe" # } # }, # "country": { # "is_in_european_union": true, # "iso_code": "DE", # "geoname_id": 2921044, # "names": { # "fr": "Allemagne", # "ja": "????????", # "pt-BR": "Alemanha", # "ru": "????????", # "zh-CN": "??", # "de": "Deutschland", # "en": "Germany", # "es": "Alemania" # } # }, # "maxmind": { # "queries_remaining": 49999 # }, # "registered_country": { # "is_in_european_union": true, # "iso_code": "DE", # "geoname_id": 2921044, # "names": { # "es": "Alemania", # "fr": "Allemagne", # "ja": "????????", # "pt-BR": "Alemanha", # "ru": "????????", # "zh-CN": "??", # "de": "Deutschland", # "en": "Germany" # } # }, # "traits": { # "ip_address": "149.250.207.170" # } # } # # set continentCode [CkJsonObject_stringOf $json "continent.code"] set continentGeoname_id [CkJsonObject_IntOf $json "continent.geoname_id"] set continentNamesJa [CkJsonObject_stringOf $json "continent.names.ja"] set continentNamesPt_BR [CkJsonObject_stringOf $json "continent.names.pt-BR"] set continentNamesRu [CkJsonObject_stringOf $json "continent.names.ru"] set continentNamesZh_CN [CkJsonObject_stringOf $json "continent.names.zh-CN"] set continentNamesDe [CkJsonObject_stringOf $json "continent.names.de"] set continentNamesEn [CkJsonObject_stringOf $json "continent.names.en"] set continentNamesEs [CkJsonObject_stringOf $json "continent.names.es"] set continentNamesFr [CkJsonObject_stringOf $json "continent.names.fr"] set countryIs_in_european_union [CkJsonObject_BoolOf $json "country.is_in_european_union"] set countryIso_code [CkJsonObject_stringOf $json "country.iso_code"] set countryGeoname_id [CkJsonObject_IntOf $json "country.geoname_id"] set countryNamesFr [CkJsonObject_stringOf $json "country.names.fr"] set countryNamesJa [CkJsonObject_stringOf $json "country.names.ja"] set countryNamesPt_BR [CkJsonObject_stringOf $json "country.names.pt-BR"] set countryNamesRu [CkJsonObject_stringOf $json "country.names.ru"] set countryNamesZh_CN [CkJsonObject_stringOf $json "country.names.zh-CN"] set countryNamesDe [CkJsonObject_stringOf $json "country.names.de"] set countryNamesEn [CkJsonObject_stringOf $json "country.names.en"] set countryNamesEs [CkJsonObject_stringOf $json "country.names.es"] set maxmindQueries_remaining [CkJsonObject_IntOf $json "maxmind.queries_remaining"] set registered_countryIs_in_european_union [CkJsonObject_BoolOf $json "registered_country.is_in_european_union"] set registered_countryIso_code [CkJsonObject_stringOf $json "registered_country.iso_code"] set registered_countryGeoname_id [CkJsonObject_IntOf $json "registered_country.geoname_id"] set registered_countryNamesEs [CkJsonObject_stringOf $json "registered_country.names.es"] set registered_countryNamesFr [CkJsonObject_stringOf $json "registered_country.names.fr"] set registered_countryNamesJa [CkJsonObject_stringOf $json "registered_country.names.ja"] set registered_countryNamesPt_BR [CkJsonObject_stringOf $json "registered_country.names.pt-BR"] set registered_countryNamesRu [CkJsonObject_stringOf $json "registered_country.names.ru"] set registered_countryNamesZh_CN [CkJsonObject_stringOf $json "registered_country.names.zh-CN"] set registered_countryNamesDe [CkJsonObject_stringOf $json "registered_country.names.de"] set registered_countryNamesEn [CkJsonObject_stringOf $json "registered_country.names.en"] set traitsIp_address [CkJsonObject_stringOf $json "traits.ip_address"] delete_CkHttp $http delete_CkJsonObject $json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.