Crate gip

Source
Expand description

This crate provides a library for checking global IP address. This crate get IP address information from IP address checking services like inet-ip.info, ipify.org, etc.

§Usage

This crate can be used by adding gip to your dependencies in Cargo.toml.

[dependencies]
gip = "0.7.1"

§Example

Provider trait provide get_addr function to check global IP address. ProviderDefaultV4 is a Provider implementation with built-in providers for IPv4 address.

use gip::{Provider, ProviderDefaultV4};
let mut p = ProviderDefaultV4::new();
let addr = p.get_addr();
match addr {
    Ok(x) => println!( "Global IPv4 address is {:?}", x.v4addr ),
    Err(_) => (),
}

ProviderDefaultV6 is for IPv6 address.

use gip::{Provider, ProviderDefaultV6};
let mut p = ProviderDefaultV6::new();
let addr = p.get_addr();
match addr {
    Ok(x) => println!( "Global IPv6 address is {:?}", x.v6addr ),
    Err(_) => (),
}

ProviderDefaultV4 and ProviderDefaultV6 tries the next provider if a provider is failed to access. So get_addr successes unless all providers failed.

§Built-in providers

ProviderDefaultV4 and ProviderDefaultV6 use the built-in provider list ( defined as DEFAULT_TOML ):

Structs§

GlobalAddress
Global address information
ProviderAny
A Provider implementation to try multiple providers
ProviderDefaultV4
A convinient wrapper of ProviderAny with default providers for IPv4
ProviderDefaultV6
A convinient wrapper of ProviderAny with default providers for IPv6
ProviderDns
A Provider implementation for checking global address through DNS. url should be [request domain name]@[resolver address].
ProviderHttpJson
A Provider implementation for checking global address by JSON format.
ProviderHttpPlane
A Provider implementation for checking global address by plane text format.
ProviderInfo
Provider information
ProviderInfoList
Provider information list

Enums§

Error
ProviderInfoProtocol
Protocol of provider
ProviderInfoType
Type of global address from provider

Statics§

DEFAULT_TOML
Built-in providers list

Traits§

Provider
Provider describes types that can provide global address information