Rust
Rust
ipdata.co IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the ipdata.co API.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
let Ok(json_str) = http.quick_get_str("https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY") else {
println!("{}", http.last_error_text());
return;
};
let json = chilkat::JsonObject::new();
json.set_emit_compact(false);
let _ = json.load(&json_str).is_ok();
println!("{}", json.emit().unwrap_or_default());
// Sample output:
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "ip": "149.250.207.170",
// "is_eu": true,
// "city": null,
// "region": null,
// "region_code": null,
// "country_name": "Germany",
// "country_code": "DE",
// "continent_name": "Europe",
// "continent_code": "EU",
// "latitude": 51.2993,
// "longitude": 9.491,
// "asn": "AS15854",
// "organisation": "EntServ Deutschland GmbH",
// "postal": null,
// "calling_code": "49",
// "flag": "https://ipdata.co/flags/de.png",
// "emoji_flag": "\ud83c\udde9\ud83c\uddea",
// "emoji_unicode": "U+1F1E9 U+1F1EA",
// "languages": [
// {
// "name": "German",
// "native": "Deutsch"
// }
// ],
// "currency": {
// "name": "Euro",
// "code": "EUR",
// "symbol": "\u20ac",
// "native": "\u20ac",
// "plural": "euros"
// },
// "time_zone": {
// "name": "Europe/Berlin",
// "abbr": "CEST",
// "offset": "+0200",
// "is_dst": true,
// "current_time": "2019-04-20T23:54:30.715507+02:00"
// },
// "threat": {
// "is_tor": false,
// "is_proxy": false,
// "is_anonymous": false,
// "is_known_attacker": false,
// "is_known_abuser": false,
// "is_threat": false,
// "is_bogon": false
// },
// "count": "2"
// }
let mut i: i32 = 0;
let ip = json.string_of("ip").unwrap_or_default();
let is_eu = json.bool_of("is_eu");
let city = json.string_of("city").unwrap_or_default();
let region = json.string_of("region").unwrap_or_default();
let region_code = json.string_of("region_code").unwrap_or_default();
let country_name = json.string_of("country_name").unwrap_or_default();
let country_code = json.string_of("country_code").unwrap_or_default();
let continent_name = json.string_of("continent_name").unwrap_or_default();
let continent_code = json.string_of("continent_code").unwrap_or_default();
let latitude = json.string_of("latitude").unwrap_or_default();
let longitude = json.string_of("longitude").unwrap_or_default();
let asn = json.string_of("asn").unwrap_or_default();
let organisation = json.string_of("organisation").unwrap_or_default();
let postal = json.string_of("postal").unwrap_or_default();
let calling_code = json.string_of("calling_code").unwrap_or_default();
let flag = json.string_of("flag").unwrap_or_default();
let emoji_flag = json.string_of("emoji_flag").unwrap_or_default();
let emoji_unicode = json.string_of("emoji_unicode").unwrap_or_default();
let currency_name = json.string_of("currency.name").unwrap_or_default();
let currency_code = json.string_of("currency.code").unwrap_or_default();
let currency_symbol = json.string_of("currency.symbol").unwrap_or_default();
let currency_native = json.string_of("currency.native").unwrap_or_default();
let currency_plural = json.string_of("currency.plural").unwrap_or_default();
let time_zone_name = json.string_of("time_zone.name").unwrap_or_default();
let time_zone_abbr = json.string_of("time_zone.abbr").unwrap_or_default();
let time_zone_offset = json.string_of("time_zone.offset").unwrap_or_default();
let time_zone_is_dst = json.bool_of("time_zone.is_dst");
let time_zone_current_time = json.string_of("time_zone.current_time").unwrap_or_default();
let threat_is_tor = json.bool_of("threat.is_tor");
let threat_is_proxy = json.bool_of("threat.is_proxy");
let threat_is_anonymous = json.bool_of("threat.is_anonymous");
let threat_is_known_attacker = json.bool_of("threat.is_known_attacker");
let threat_is_known_abuser = json.bool_of("threat.is_known_abuser");
let threat_is_threat = json.bool_of("threat.is_threat");
let threat_is_bogon = json.bool_of("threat.is_bogon");
let count = json.string_of("count").unwrap_or_default();
i = 0;
let count_i = json.size_of_array("languages");
while i < count_i {
json.set_i(i);
let _ = json.string_of("languages[i].name").unwrap_or_default();
let _ = json.string_of("languages[i].native").unwrap_or_default();
i = i + 1;
}