Crate gip[−][src]
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.6.0"
and this to your crate root:
extern crate gip;
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
):
- inet-ip.info ( v4 only )
- ipify.org ( v4 only )
- ipv6-test.com ( v4 /v6 )
- ident.me ( v4 / v6 )
- test-ipv6.com ( v4 / v6 )
Structs
Error |
The Error type. |
GlobalAddress |
Global address information |
ProviderAny |
A |
ProviderDefaultV4 |
A convinient wrapper of |
ProviderDefaultV6 |
A convinient wrapper of |
ProviderInfo |
Provider information |
ProviderInfoList |
Provider information list |
ProviderJson |
A |
ProviderPlane |
A |
Enums
ErrorKind |
The kind of an error. |
ProviderInfoFormat |
Format of return value from 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 |
ResultExt |
Additional methods for |
Type Definitions
Result |
Convenient wrapper around |