This crate exposes a struct called Looker that you need to instantiate like this:
use ;
let file_path = from_str.expect;
let looker = new;
You can then use the looker variable to call the look_up method like this to get a IP result with Country, Region and City:
let ip = new;
let result = looker.look_up_ipv4;
match result
Or if you only have a string as an IP:
let ip = "12.22.104.13";
let result = looker.look_up;
match result
llows you to filter on countries when building the Looker. Useful if you only care about a few countries to reduce memory usage:
let file_path = from_str.expect;
let allowed_countries = vec!; // Note they must match the country names in the csv file
let looker = builder
.file_path
.allowed_countries
.build
.expect;
let ip = "12.22.104.13";
let result = looker.look_up;
match result
You can download the ip .csv file from here: https://cable.ayra.ch/ip/data/locationv4.gz
And then unzip it with:
gzip -d locationv4.gz
The file needs to have the .csv extension. If it doesn't have it after you unzip it, add it.
History
- 0.1.5 - Breaking change: Needs a PathBuf instead of a string to load the csv. New function called look_up_ipv4 that takes an Ipv4Addr instead of a string.