Function getip::get_ip[][src]

pub async fn get_ip(
    ip_type: IpType,
    ip_scope: IpScope,
    nic: Option<&str>
) -> Result<IpAddr>
Expand description

Receive a IP address of family ip_type that has a scope of ip_scope on an interface named nic.

If ip_scope is Global, the address is received from an external service, and nic is ignored. If nic is None, this function uses the first one returned by the OS.

Examples

Get an global IPv4 address:

use getip::get_ip;
use getip::{IpScope, IpType, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let address = get_ip(IpType::Ipv4, IpScope::Global, None).await?;
    println!("{}", address);
    Ok(())
}

Errors

Any errors returned by the underlying provider is propagated here.