STUN

在 linux 上安裝 stun package

$ sudo apt-get install stun

如果有多個 NIC, 建議以 -i 提定出口 ip, 例如 eth0 的 ip 為 192.168.1.62, STUN IP 為 stun.stunprotocol.org, 可這麼執行

$ stun stun.stunprotocol.org -i 192.168.1.62 -v
STUN client version 0.96
Binding to interface 0x3e01a8c0
Opened port 31729 with fd 3
Binding to interface 0x3e01a8c0
Opened port 31730 with fd 4
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 4

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 2

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 4

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 2

About to send msg of len 28 to 52.5.57.211:3478
Received stun message: 68 bytes
MappedAddress = 140.206.137.5:28249
SourceAddress = 52.5.57.211:3478
ChangedAddress = 52.4.176.186:3479
XorMappedAddress = 140.206.137.5:28249
Received message of type 257  id=1
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 52.4.176.186:3478
Encoding stun message: 
Encoding ChangeRequest: 4

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 2

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 140.206.137.5:28249
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 52.4.176.186:3478
Encoding stun message: 
Encoding ChangeRequest: 4

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 2

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 140.206.137.5:28249
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 52.4.176.186:3478
Encoding stun message: 
Encoding ChangeRequest: 4

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 2

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 140.206.137.5:28249
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 52.4.176.186:3478
Encoding stun message: 
Encoding ChangeRequest: 4

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 2

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 140.206.137.5:28249
Received stun message: 68 bytes
MappedAddress = 140.206.137.5:29412
SourceAddress = 52.4.176.186:3478
ChangedAddress = 52.5.57.211:3479
XorMappedAddress = 140.206.137.5:29412
Received message of type 257  id=10
Encoding stun message: 
Encoding ChangeRequest: 4

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 2

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 140.206.137.5:28249
Encoding stun message: 
Encoding ChangeRequest: 4

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 2

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 140.206.137.5:28249
Encoding stun message: 
Encoding ChangeRequest: 4

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 2

About to send msg of len 28 to 52.5.57.211:3478
Encoding stun message: 
Encoding ChangeRequest: 0

About to send msg of len 28 to 140.206.137.5:28249
test I = 1
test II = 0
test III = 0
test I(2) = 1
is nat  = 1
mapped IP same = 0
hairpin = 0
preserver port = 0
Primary: Dependent Mapping, random port, no hairpin	
Return value is 0x000018

Primary: Dependent Mapping, random port, no hairpin 代表 NAT 型態, 可參考以下 link
http://albert-oma.blogspot.jp/2013/01/nat-stun.html

經由 Web Browser 測試

連上這頁
https://plugin.temasys.com.sg/demo/samples/web/content/peerconnection/trickle-ice/index.html

鍵入 stun/turn server 資訊, 點擊最下方 "Gather Candidates" 即可.