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
(PowerBuilder) MaxMind IPv4 Geolocation LookupDemonstrates how to lookup Geolocation data for an IPv4 address using the MaxMind GeoIP2 Precision Web Service.
integer li_rc oleobject loo_Http string ls_JsonStr oleobject loo_Json integer li_Success string ls_ContinentCode integer li_ContinentGeoname_id string ls_ContinentNamesJa string ls_ContinentNamesPt_BR string ls_ContinentNamesRu string ls_ContinentNamesZh_CN string ls_ContinentNamesDe string ls_ContinentNamesEn string ls_ContinentNamesEs string ls_ContinentNamesFr integer li_CountryIs_in_european_union string ls_CountryIso_code integer li_CountryGeoname_id string ls_CountryNamesFr string ls_CountryNamesJa string ls_CountryNamesPt_BR string ls_CountryNamesRu string ls_CountryNamesZh_CN string ls_CountryNamesDe string ls_CountryNamesEn string ls_CountryNamesEs integer li_MaxmindQueries_remaining integer li_Registered_countryIs_in_european_union string ls_Registered_countryIso_code integer li_Registered_countryGeoname_id string ls_Registered_countryNamesEs string ls_Registered_countryNamesFr string ls_Registered_countryNamesJa string ls_Registered_countryNamesPt_BR string ls_Registered_countryNamesRu string ls_Registered_countryNamesZh_CN string ls_Registered_countryNamesDe string ls_Registered_countryNamesEn string ls_TraitsIp_address // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if loo_Http.Login = "MAXMIND_ACCOUNT_ID" loo_Http.Password = "MAXMIND_LICENSE_KEY" loo_Http.Accept = "application/json" // Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address) ls_JsonStr = loo_Http.QuickGetStr("https://geoip.maxmind.com/geoip/v2.1/country/149.250.207.170") if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http return end if loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.EmitCompact = 0 li_Success = loo_Json.Load(ls_JsonStr) Write-Debug loo_Json.Emit() // 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" // } // } // // ls_ContinentCode = loo_Json.StringOf("continent.code") li_ContinentGeoname_id = loo_Json.IntOf("continent.geoname_id") ls_ContinentNamesJa = loo_Json.StringOf("continent.names.ja") ls_ContinentNamesPt_BR = loo_Json.StringOf("continent.names.pt-BR") ls_ContinentNamesRu = loo_Json.StringOf("continent.names.ru") ls_ContinentNamesZh_CN = loo_Json.StringOf("continent.names.zh-CN") ls_ContinentNamesDe = loo_Json.StringOf("continent.names.de") ls_ContinentNamesEn = loo_Json.StringOf("continent.names.en") ls_ContinentNamesEs = loo_Json.StringOf("continent.names.es") ls_ContinentNamesFr = loo_Json.StringOf("continent.names.fr") li_CountryIs_in_european_union = loo_Json.BoolOf("country.is_in_european_union") ls_CountryIso_code = loo_Json.StringOf("country.iso_code") li_CountryGeoname_id = loo_Json.IntOf("country.geoname_id") ls_CountryNamesFr = loo_Json.StringOf("country.names.fr") ls_CountryNamesJa = loo_Json.StringOf("country.names.ja") ls_CountryNamesPt_BR = loo_Json.StringOf("country.names.pt-BR") ls_CountryNamesRu = loo_Json.StringOf("country.names.ru") ls_CountryNamesZh_CN = loo_Json.StringOf("country.names.zh-CN") ls_CountryNamesDe = loo_Json.StringOf("country.names.de") ls_CountryNamesEn = loo_Json.StringOf("country.names.en") ls_CountryNamesEs = loo_Json.StringOf("country.names.es") li_MaxmindQueries_remaining = loo_Json.IntOf("maxmind.queries_remaining") li_Registered_countryIs_in_european_union = loo_Json.BoolOf("registered_country.is_in_european_union") ls_Registered_countryIso_code = loo_Json.StringOf("registered_country.iso_code") li_Registered_countryGeoname_id = loo_Json.IntOf("registered_country.geoname_id") ls_Registered_countryNamesEs = loo_Json.StringOf("registered_country.names.es") ls_Registered_countryNamesFr = loo_Json.StringOf("registered_country.names.fr") ls_Registered_countryNamesJa = loo_Json.StringOf("registered_country.names.ja") ls_Registered_countryNamesPt_BR = loo_Json.StringOf("registered_country.names.pt-BR") ls_Registered_countryNamesRu = loo_Json.StringOf("registered_country.names.ru") ls_Registered_countryNamesZh_CN = loo_Json.StringOf("registered_country.names.zh-CN") ls_Registered_countryNamesDe = loo_Json.StringOf("registered_country.names.de") ls_Registered_countryNamesEn = loo_Json.StringOf("registered_country.names.en") ls_TraitsIp_address = loo_Json.StringOf("traits.ip_address") destroy loo_Http destroy loo_Json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.