Crates.io | rmw-stun |
lib.rs | rmw-stun |
version | 0.0.3 |
source | src |
created_at | 2021-11-17 08:33:06.690483 |
updated_at | 2021-11-18 09:08:07.697394 |
description | get external ip port via stun server |
homepage | |
repository | https://github.com/rmw-lib/node/tree/master/stun |
max_upload_size | |
id | 483210 |
size | 32,357 |
get external ip port via stun server
use async_std::net::UdpSocket;
use rmw_stun::external_addr;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::time::{Instant};
#[async_std::main]
async fn main() {
let udp = UdpSocket::bind(SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0))
.await
.unwrap();
//let server = "not.exist.stun:3478";
let server = "stun.cablenet-as.net:3478";
let timeout = 3;
let start = Instant::now();
let addr = external_addr(&udp, server, timeout).await;
let duration = start.elapsed();
println!("external addr {:?} cost {:?}", addr, duration);
}
output as below
external addr Ok(54.177.127.37:40143) cost 402.976326ms
本项目隶属于人民网络(rmw.link) 代码计划。