Skip to content

kawloong/NatDetect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

NatDetect

Detect client's local network on which type of NAT

测试用户所在环境的NAT设备类型 NAT1: Full Cone NAT2: Restricted Cone NAT3: Port-Restricted Cone NAT4: Symmetric

拓普模型: 两服务端 + 一客户端,服务端要求有有独立公网IP,至少一台, 客户端在要测试的网络环境机器上执行, 服务端的防火墙需放行相关的UDP端口 C(client) __________________________|_____________________________ 1| ↑8 2| ↑7 ↑6 ↑9 10| ↑11 ↓ | ↓ | | | | | Server1 S1:P1 S1:P2 S1:P3 | | | |----------------------------------------↑3 4 5 | ↓ | Server2 +----------------------------------------------------→ S2:P1 -------------→ S2:P2 ------------→ S2:P3

序列图: (UDP响应无顺序性,6/7/8/9先后到达不影响) c S1:P1 S1:P2 S1:P3 S2:P1 S2:P2 S2:P3 | | | | | | | |---------->| 1 | | | | | |-----------+----------->|2 | | | | |<----------+------------| | | | | |7 | | | | | | | |------------+---------->|3 | | | | |------------+-----------+-------------------->|4 | | |6 | | | +----------->|5 | |<----------+------------------------| | | | |8 | | | | | | |<----------+ | | | | | | | | | | | | <----------+------------+-----------+---------------------+------------| | |9 | | | | | | | | | | | | | | | | | | | | |-----------+------------+-----------+---------------------+------------+------------->|10 |<----------+------------+-----------+---------------------+------------+--------------|11 | | | | | | | | | | | | | | | | | | | | |

响应的rStep(程序内的标识响应的身份)与上面时序标号关系: rStep1 <---> 8 rStep2 <---> 7 rStep3 <---> 3 rStep4 <---> 9 rStep5 <---> 11

传参: s1: 服务端1 s2: 服务端2 [可选,没有时会降低准确度] c: 客户端

运行环境注意: 此工具服务端和客户端都使本同一程序文件,服务端要求有两个公网IP(相应端口不能被防火墙拦截),客户端要求能连通公网;

使用示例:

  1. 获得natchk.py文件之后,修改程序开始处的服务器地址 s1_ip='第一台具备公网IP的机器' (本文件85行) s2_ip='第二台具备公网IP的机器' (本文件90行)
  2. 运行服务端程序 第一台上运行 python natchk.py s1 第二台上运行 python natchk.py s2
  3. 在待检测的环境运行客户端程序 python natchk.py c 网络正常的话10内打印出检测结果 结果输出样式Test Summery: NAT3 Port Restricted

About

Detect client's local network on which type of NAT

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published