#public-ip #ip-address #stun #server #machine #determine #nat

app uip

一个工具,通过 STUN 服务器快速确定 NAT 背后的机器的公网 IP 地址。

7 个版本

0.1.6 2023 年 4 月 13 日
0.1.5 2023 年 4 月 12 日

#1648 in 网络编程

每月 26 次下载

MIT/Apache

17KB
70

uip

一个工具,通过 STUN 服务器快速确定 NAT 背后的机器的公网 IP 地址。

概述

这个工具非常简单,执行后通过向 STUN 服务器发送绑定请求,并显示 STUN 服务器返回的 XOR-MAPPED-ADDRESSMAPPED-ADDRESS 属性来输出当前机器的公网 IP 地址。

安装

您可以从发布页面下载预构建的二进制文件,或者使用 cargo install uip 来安装它。

用法

$ uip -h
A tool to quickly determine the public IP address of a machine behind
NAT with the help of STUN servers.


Usage: uip [OPTIONS] [HOST:PORT]

Arguments:
  [HOST:PORT]  STUN server host and port. If PORT is omitted, it defaults to 3478 [default: stun.cloudflare.com]

Options:
  -4, --ipv4-only  Do not use IPv6 addresses when connecting to STUN server
  -h, --help       Print help
  -V, --version    Print version

默认端口(UDP 3478)

$ uip stun.cloudflare.com
203.0.113.1

自定义端口

$ uip stun.l.google.com:19302
203.0.113.1

此程序使用返回代码 0 表示成功并返回了有效的 IP 地址。所有其他返回代码表示错误。

如果无法收到响应,程序将在 5 秒后超时。

要调试,请使用 RUST_LOG=debug uip 运行。

公共 STUN 服务器

  • stun.cloudflare.com
  • stun.l.google.com
  • stun1.l.google.com
  • stun2.l.google.com
  • stun3.l.google.com
  • stun4.l.google.com
  • stun.syncthing.net
  • stun.xten.com

中国服务器

  • stun.qq.com
  • stun.miwifi.com
  • stun.chat.bilibili.com

public-stun-list.txt(未经验证)

致谢

此脚本由 Rain Liu 的 stun_client.rs 示例修改而来,该示例来自 WebRTC.rs 项目,联系邮箱为 [email protected]

uip 增强了错误处理,提供了更友好的命令行界面,并在找不到 XOR-MAPPED-ADDRESS 属性时回退到 MAPPED-ADDRESS 属性。因为一些服务器测试中不返回 XOR-MAPPED-ADDRESS

许可证

版权所有 2023 孙大同 ([email protected])

在 Apache License 2.0 <LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0> 或 MIT 许可证 <LICENSE-MIT 或 https://opensource.org/licenses/MIT> 下获得许可,您可选择其中一种。项目中的文件不得根据这些条款进行复制、修改或分发。

依赖

~15–28MB
~524K SLoC