3 releases

0.0.3 Nov 18, 2021
0.0.2 Nov 18, 2021
0.0.1 Nov 17, 2021

#5 in #addr

AGPL-3.0-or-later

10KB
99 lines

rmw-stun

get external ip port via stun server

use example

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) 代码计划。

人民网络

Dependencies

~17–31MB
~591K SLoC