Crates.io | stunclient |
lib.rs | stunclient |
version | 0.4.1 |
source | src |
created_at | 2019-01-31 23:54:42.170933 |
updated_at | 2024-05-21 14:35:05.456544 |
description | Simple STUN client for resolving external IP address and port of a UDP socket |
homepage | |
repository | https://github.com/vi/rust-stunclient |
max_upload_size | |
id | 111895 |
size | 25,094 |
Simple UDP-only STUN client for resolving external IP address:port behind NAT.
Supports both sync and async.
Example (sync):
use std::net::UdpSocket;
use stunclient::StunClient;
use std::net::{SocketAddr,ToSocketAddrs};
let local_addr : SocketAddr = "0.0.0.0:0".parse().unwrap();
let stun_addr = "stun.l.google.com:19302".to_socket_addrs().unwrap().filter(|x|x.is_ipv4()).next().unwrap();
let udp = UdpSocket::bind(local_addr).unwrap();
let c = StunClient::new(stun_addr);
let my_external_addr = c.query_external_address(&udp).unwrap();
Example (async):
use stunclient::StunClient;
use std::net::{SocketAddr,ToSocketAddrs};
let local_addr : SocketAddr = "0.0.0.0:0".parse().unwrap();
let stun_addr = "stun.l.google.com:19302".to_socket_addrs().unwrap().filter(|x|x.is_ipv4()).next().unwrap();
let udp = tokio::net::udp::UdpSocket::bind(&local_addr).unwrap();
let c = StunClient::new(stun_addr);
let f = c.query_external_address_async(&udp);
let my_external_addr = f.await.unwrap();
Old version (0.1) of stunclient is almost the same, but is for Tokio 0.1
.