seeip

Crates.ioseeip
lib.rsseeip
version3.0.1
sourcesrc
created_at2022-04-04 11:05:11.294635
updated_at2024-08-05 18:14:46.816367
descriptionRust Wrapper for the IP Info https://seeip.org/ API
homepagehttps://github.com/mark-ruddy/seeip
repositoryhttps://github.com/mark-ruddy/seeip
max_upload_size
id561934
size47,741
Mark Ruddy (mark-ruddy)

documentation

README

seeip

Rust Wrapper for the IP Info https://seeip.org/ API
See example project using this seeip library: https://github.com/mark-ruddy/ipfetch

Examples

All of the below examples support both IPv4 and IPv6 addresses.
To specifically use either IPv4 or IPv6 use their _v4() and _v6() equivalents.

Get the caller's IP address

let my_ip = seeip::get_ip().unwrap();
println!("My IP: {}", my_ip);

Get the caller's geographical information

let my_geo_info = seeip::get_caller_geo().unwrap();
// Fields in GeoInfo can default out to empty values if not available from the API
println!("Country my IP matches: {}", my_geo_info.country);

Get geographical information for an IP address

let geo_info = seeip::get_geo("208.67.222.222").unwrap();
println!("Country matching this IP: {}", geo_info.country);

Testing

The tests involve making actual API calls. This means that they can fail if you make an IPv6-only call when your host does not support IPv6:

If you are on a host supporting both IPv4 and IPv6: cargo test --verbose
For a host that only supports IPv4: cargo test --verbose -- --skip v6
For a host that only supports IPv6: cargo test --verbose -- --skip v4

Commit count: 25

cargo fmt