The client (based on ip-api.com api) allows you to get information about the IP address
Add to project
toml
[dependencies]
ip-api-client = "0.4.0"
Write some Rust
```rust use ipapiclient as Client; use ipapiclient::{IpApiLanguage, IpData};
fn main() {
// You can
// generate_empty_config
(to create your own config from scratch)
// generate_minimum_config
(that includes only important fields)
// generate_maximum_config
(that includes all fields)
let ipdata: IpData = Client::generateemptyconfig()
// or exclude_country
if this field is already included in the generated config
.includecountry()
// or exclude_currency
if this field is already included in the generated config
.includecurrency()
// available languages: de/en (default)/es/fr/ja/pt-Br/ru/zh-CN
.setlanguage(IpApiLanguage::De)
// make_request
takes "ip"/"domain"/"empty string (if you want to request your ip)"
.make_request("1.1.1.1").unwrap();
println!("{}'s national currency is {}", ipdata.country.unwrap(), ipdata.currency.unwrap());
// If you want to request more than one ip, you can use make_batch_request
let ipbatchdata: Vecmake_batch_request
takes "IPv4"/"IPv6"
.makebatch_request(vec!["1.1.1.1", "8.8.8.8"]).unwrap();
println!(
"1.1.1.1 belongs to {}
and 8.8.8.8 belongs to {}
",
ipbatchdata.get(0).unwrap().isp.asref().unwrap(),
ipbatchdata.get(1).unwrap().isp.asref().unwrap(),
);
}
```
as_field
instead of as
(As stated in the ip-api.com API documentation)
since it is a strict keyword in rust,
such as pub
, impl
or struct
.This library (ip-api-client) is available under the MIT license. See the LICENSE file for more info.