把源码 clone 下来:
$ git clone https://github.com/jselbie/stunserver.git
进入源码目录,在这之前确保 boost 库已经编译好了(我的 boost 安装在 /opt/local
):
CXX=$(xcrun --find clang++) \
CXXFLAGS="-std=gnu++17 -isysroot $(xcrun --show-sdk-path) -I/opt/local/include" \
make
然后把编译出来的三个程序放到 bin 目录下就可以使用了,我自己使用的目录是(/opt/local/bin
):
$ sudo cp ./stunserver /opt/local/bin
$ sudo cp ./stunclient /opt/local/bin
$ sudo cp ./stuntestcode /opt/local/bin
然后测试一下:
$ stunclient stun.miwifi.com --mode behavior
Binding test: success
Local address: 10.1.1.2:52950
Mapped address: 116.31.232.169:43799
Behavior test: success
Nat behavior: Endpoint Independent Mapping
在这里可以下载预编译好的程序: https://github.com/cntrump/stunserver/releases