#ip-address #ip-lookup #country #check #region #city #looker

bin+lib ip-check

Check in what country an IP address is located

5 releases

0.1.4 Sep 28, 2024
0.1.3 Sep 27, 2024
0.1.2 Sep 27, 2024
0.1.1 Sep 26, 2024
0.1.0 Sep 26, 2024

#1839 in Network programming

Download history 372/week @ 2024-09-23 59/week @ 2024-09-30 5/week @ 2024-10-07 25/week @ 2024-10-14 42/week @ 2024-10-21 19/week @ 2024-10-28

91 downloads per month

MIT license

8KB
159 lines

This crate exposes a struct called Looker that you need to instantiate like this:

use ip_check::{Looker, IpLookup};


let looker = Looker::new(file_path.to_string());

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 = "12.22.104.13";
    let result = looker.look_up(ip);
    match result {
        Some(ip_range) => {
            println!("Country: {}", ip_range.country);
            println!("Region: {}", ip_range.region);
            println!("City: {}", ip_range.city);
        },
        None => {
            println!("No match found");
        }
    }

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.

24HR-ip-check

Dependencies

~1.2–1.6MB
~19K SLoC