飘在云端

东西南北,海角天涯

· 备查 · · 188次浏览

安卓/Windows Termux 安装 pynat 查询 UDP 支持及 NAT 等级

自行解决 Termux、python 官方源速度问题,推荐使用魔法或者配置镜像源

更新:2024-03-03,如果安装部分依赖时报错,443端口的 SSL证书错误,例如 https://pypi.org/simple/xxxxx/xxxxxxx:443 SSL xxxxx
为梯子问题,自行更换其他节点再次重试


测试环境:
Termux v0.118.0
MIUI 13.0.11 稳定版、安卓12
Python 2.7.18、pip2 19.2.3
Clash for Androud 3.0.3 premium + Shizuku 启动模式 + TUN

备注:无需 ROOT,跨平台,windows 自行配置 python2 环境和 python 代理

初始环境下,我们先安装一些依赖

pkg install python2
pip2 install six ipaddress
pip2 install pynat

最后执行 pynat -h,返回

~ $ pynat -h
usage: pynat [-h] [--source_ip SOURCE_IP] [--source-port SOURCE_PORT]
             [--stun-host STUN_HOST] [--stun-port STUN_PORT]

PyNAT v0.7.0 Discover external IP addresses and NAT topologies using STUN.
Copyright (C) 2022 Ariel A. Licensed under the MIT License.

optional arguments:
  -h, --help            show this help message and exit
  --source_ip SOURCE_IP
                        The source IPv4/IPv6 address to bind to.
  --source-port SOURCE_PORT
                        The source port to bind to.
  --stun-host STUN_HOST
                        The STUN host to use for queries.
  --stun-port STUN_PORT
                        The port of the STUN host to use for queries.

使用默认配置运行,直接执行 pynat,返回

~ $ pynat
('Network type:', 'Full-cone NAT', '\nInternal address: 172.19.0.1:54320', '\nExternal address: 1.1.1.1:57926')

我这里使用了深港专线,使用的 shadowsocks(sip008)协议,服务端开放了 UDP 支持,结果中的 IP 1.1.1.1 为你的外网IP(代理IP),Full-cone NAT 是你的 NAT 等级,这里是 NAT 1,完全体的 NAT

请输入图片描述

或者使用自定义 stun 服务器

pynat --stun-host stun.qq.com --stun-port 3478

不过这里测试输出了 Symmetric NAT 的类型,因为此时没被代理,Clash 分流国内使用本地网络直连了(移动5G),大内网哈哈哈哈

评论 (0条)