線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:6253
推到 Plurk!
推到 Facebook!

請問有什麼方法可以偵測NAT的類型呢?

缺席
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-07 19:31:32 IP:61.228.xxx.xxx 未訂閱
小弟想寫一個偵測NAT的類型程式. 小只知道STUN的原理,但是用IdUDPClient/IdUDPServer的方式寫出這程式,卻不知道怎麼下手? 請問各位,這需要用什麼方法可以寫出Client/Server的程式呢? p.s:安全機制(定義USERNAME、PASSWORD的Message Type)可忽略的情況下,就單純只要偵測"該網路是哪一種類型的NAT"!     ※從圖一其實可以知道,Server會有兩組ip跟port. 注意,請看TestII的"綠色箭頭"部分! 另外,STUN的Server一定要是Public 的IP Address(實體IP Address),如此才可以達到測試的目的. ※根據圖二就可知道Test的過程,以及哪些部分的Test需要用到Server兩組ip與port做Binding Request/Response. 另外補充說明,NAT有4種類型: 1.ConeNat (Full Cone) - 完全透明NAT 2.RestrictedNat (Restricted Cone) - 限制(ip)型的NAT 3.PortRestrictedNat (Port Restricted Cone) - Port限制型的NA(ip & port) 4.SymNat (Symmetric) - 對稱型的NAT(這也是最難搞定的,但是可以透過Relay的中繼方式解決,但是需要額外的硬體設備,成本提高!) ----------------------- 請多多指教啦!!^^ 發表人 - kj68215 於 2004/08/07 19:37:56 發表人 - kj68215 於 2004/08/07 19:44:14
------
-----------------------
請多多指教啦!!^^
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-08-07 23:49:32 IP:220.136.xxx.xxx 未訂閱
抱歉,小弟不小心把此帖給結案為"缺席"了! 其實這也是今天才post的問題啦,想問看看大家是否知道?! 幫忙解決小弟的問題! ----------------------- 請多多指教啦!!^^
------
-----------------------
請多多指教啦!!^^
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-08-08 02:59:13 IP:61.64.xxx.xxx 未訂閱
kj68215 兄 請問一下 為何要偵測nat類型 是為了要穿透nat所以才偵測嗎?
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-08-08 06:15:50 IP:220.136.xxx.xxx 未訂閱
引言: kj68215 兄 請問一下 為何要偵測nat類型 是為了要穿透nat所以才偵測嗎?
是的,也可以這麼說! 在Client to Binding Reguest / Server Response to Client的過程中... 這都需要經過STUN Server達到目的,穿透與否,就可以獲得到NAT是哪一種類型! STUN這算是滿新的技術,RFC 3489白皮書就是在講STUN! 有興趣的話,倒是可以去Google搜尋一下,不過原文的居多,大陸網站也有相關資料... 不過講到的部分,卻很片段! 另外,也有一些用vc寫的p2p(Win32模式)聊天軟體,很接近STUN原理,不過要做偵測的目的,還有一段距離! 重要的是,我也看不太懂那個聊天軟體的open source! 下載來玩看看吧↓ < href="http://delphi.ktop.com.tw/topic.php?TOPIC_ID=54444">http://delphi.ktop.com.tw/topic.php?TOPIC_ID=54444 ----------------------- 請多多指教啦!!^^
------
-----------------------
請多多指教啦!!^^
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-08-08 12:51:21 IP:61.64.xxx.xxx 未訂閱
【分享】eMule是一個遵循GPL協定的開放源碼p2p軟體 http://delphi.ktop.com.tw/topic.php?topic_id=50181 【轉貼】比特精靈v2.0 p2p BT軟體 http://delphi.ktop.com.tw/topic.php?topic_id=52663 2個都有開放 原始碼 去搜索有關 使用GNU Gatekeepe 應該有你要的資料 http://www.gnugk.org/ RTP/RTCP在NAT上的穿透 Q931/H225/H245在NAT上的穿透 現在的 CAD/CAM 軟體 SolidWork 因使用 軟體模擬虛擬網卡 不但穿透防火牆 更建立於VPN(Virtual Private Network,虛擬專用網絡) 可以先玩一下此網友的程式喔 使用delphi indy9 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=41349 發表人 - conundrum 於 2004/08/08 13:23:04
microbean
初階會員


發表:1
回覆:43
積分:38
註冊:2004-04-09

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-08-09 18:28:45 IP:210.58.xxx.xxx 未訂閱
kj 兄 , 這份資料不錯 , 我不明白 , 如果你已經清楚的知道 stun 原理 , 在實作上應該不會有問題, 可以說說你的問題嗎 ? 原則上 indy 應該有辦法做到. 另外 , 關於穿透問題, 仍有一些疑惑 , 如果你知道了 是哪一種形式的 nat , 那又跟穿透有何關係 ? 如果架構上無法連接就應該無法連了.... 討論討論.. _= 沒事就 winsock 一下 =_
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-08-09 21:43:42 IP:220.132.xxx.xxx 未訂閱
引言: kj 兄 , 這份資料不錯 , 我不明白 , 如果你已經清楚的知道 stun 原理 , 在實作上應該不會有問題, 可以說說你的問題嗎 ? 原則上 indy 應該有辦法做到. 另外 , 關於穿透問題, 仍有一些疑惑 , 如果你知道了 是哪一種形式的 nat , 那又跟穿透有何關係 ? 如果架構上無法連接就應該無法連了.... 討論討論.. _= 沒事就 winsock 一下 =_
說實在的,小弟的程式功力還沒那麼厲害啦! 或許是因為還太嫩了吧?! 雖然 > 至於您說的"穿透"問題,解釋起來有一點小長... 其實把 src="http://delphi.ktop.com.tw/download/upload\54519_stun¬ï³z­ì²z.jpg"> 私人網路通過某種機制,先得到ip然後再對應到NAT上的對外ip,這樣就可以跟Public Internet的ip進行溝通!那麼,stun的Header Payload的內容 經過NAT就不需要被修改,只需要按照NAT流程來轉換Header的ip address即可. 此時,Payload的IP Address跟Header的IP Address是一致的!! stun的協定就是基於這原理來解決應用層位址轉換的問題. 發表人 - kj68215 於 2004/08/09 21:59:06
------
-----------------------
請多多指教啦!!^^
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-08-09 21:46:20 IP:220.132.xxx.xxx 未訂閱
STUN優缺點比較: stun協定最大的優點是不需要對現有的NAT/FW設備做任何改動. 由於實際的網絡環境中已有大量的NAT/FW,並且這些NAT/FW並不支持VoIP的應 用,因此若採用MIDCOM或NAT/ALGs方式來解決此問題,則需要更換現有的NAT/FW, 這是不太容易實行的方案. 除此之外,stun方式還可在多個NAT串聯的網絡環境中使用. 這也是MIDCOM方式無法做到的. stun的限制,是需要應用的程序中... 1.要支援stun client的功能. 2.不適合支持TCP協定的穿越. 3.不支援H.323應用協定. 4.無法對防火牆進行的穿越. 5.不支援對稱型NAT(Symmetric NAT) 發表人 - kj68215 於 2004/08/09 22:01:50
------
-----------------------
請多多指教啦!!^^
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#9 引用回覆 回覆 發表時間:2004-08-09 21:48:59 IP:220.132.xxx.xxx 未訂閱
NAT細分的種類的定義解釋與實例: --------------------------------------------------------------------- 1. ConeNat (Full Cone) - 完全透明NAT 定義解釋: 一個內部IP對應到相同的一個外部IP與PORT,外界可藉由此外部IP與PORT與內部IP溝通。 實例說明: Client A 內部IP 192.168.1.100. Cone Nat (Full Cone) 外部IP 61.20.30.40 PORT100 --------------------------------------------------------------------- 2. RestrictedNat (Restricted Cone) – 受限型的NAT 定義解釋: 一個內部IP對應到相同的一個外部IP與PORT,但是內部IP需先主動對目的端的IP傳送資料,目的端才可以藉由此外部IP 與PORT與內部IP溝通。 實例說明: Client A 內部IP 192.168.1.100 外部IP 123.123.123.123 PORT100 外界B IP 168.95.1.1 外界C IP 168.95.1.2 如果B要和Client A溝通,A需要先送封包至B的IP(168.95.1.1),然後B只需將資料送至123.123.123.123:100即可。 如果C要和Client A溝通,A需要先送封包至C的IP(168.95.1.2),然後C只需將資料送至123.123.123.123:100即可。 --------------------------------------------------------------------- 3. PortRestrictedNat (Port Restricted Cone) – Port受限型的NAT 定義解釋: 一個內部IP對應到相同的一個外部IP與PORT,但是內部IP需先主動對目的端的IP與PORT傳送資料, 目的端才可以藉由此外部IP與PORT與內部IP溝通。 實例說明: Client A 內部IP 192.168.1.100 外部IP 123.123.123.123 PORT100 外界B IP 168.95.1.1 PORT 200 外界C IP 168.95.1.2 PORT 300 如果B要和Client A溝通,A需要先送封包至B的IP(168.95.1.1)及PORT(200), 然後B只需將資料送至123.123.123.123:100即可。 如果C要和Client A溝通,A需要先送封包至C的IP(168.95.1.2)及PORT(200), 然後C只需將資料送至123.123.123.123:100即可。 --------------------------------------------------------------------- 4. SymNat (Symmetric) – 對稱型NAT 定義解釋: 內部IP對應到一個外部IP與PORT,內部IP需先主動對目的端的IP與PORT傳送資料,目的端才可以藉由此外部IP與PORT與內部IP溝通,但是只能對同一個目的端的IP與PORT。如果目的端的IP與PORT不同,內部IP對應到的外部IP與PORT也會變動,重新對應到不同的外部IP與PORT。 實例說明: Client A 內部IP 192.168.1.1 外部IP 123.123.123.123 PORT100 外部IP 123.123.123.123 PORT102 …… 外界B IP 168.95.1.1 PORT 200 外界C IP 168.95.1.2 PORT 300 如果B要和Client A溝通,A需要先送封包至B的IP(168.95.1.1)及PORT(200), 然後B只需將資料送至123.123.123.123:100即可。 發表人 - kj68215 於 2004/08/09 22:05:41
------
-----------------------
請多多指教啦!!^^
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#10 引用回覆 回覆 發表時間:2004-08-09 21:52:17 IP:220.132.xxx.xxx 未訂閱
RFC 3489 (全部的原文太長了,小弟把精華的部分貼出來) Abstract Simple Traversal of User Datagram Protocol (UDP) Through Network Address Translators (NATs) (STUN) is a lightweight protocol that allows applications to discover the presence and types of NATs and firewalls between them and the public Internet. It also provides the ability for applications to determine the public Internet Protocol (IP) addresses allocated to them by the NAT. STUN works with many existing NATs, and does not require any special behavior from them. As a result, it allows a wide variety of applications to work through existing NAT infrastructure. NAT Variations It is assumed that the reader is familiar with NATs. It has been observed that NAT treatment of UDP varies among implementations. The four treatments observed in implementations are: Full Cone: A full cone NAT is one where all requests from the same internal IP address and port are mapped to the same external IP address and port. Furthermore, any external host can send a packet to the internal host, by sending a packet to the mapped external address. Restricted Cone: A restricted cone NAT is one where all requests from the same internal IP address and port are mapped to the same external IP address and port. Unlike a full cone NAT, an external host (with IP address X) can send a packet to the internal host only if the internal host had previously sent a packet to IP address X. Port Restricted Cone: A port restricted cone NAT is like a restricted cone NAT, but the restriction includes port numbers. Specifically, an external host can send a packet, with source IP address X and source port P, to the internal host only if the internal host had previously sent a packet to IP address X and port P. Symmetric: A symmetric NAT is one where all requests from the same internal IP address and port, to a specific destination IP address and port, are mapped to the same external IP address and port. If the same host sends a packet with the same source address and port, but to a different destination, a different mapping is used. Furthermore, only the external host that receives a packet can send a UDP packet back to the internal host. Overview of Operation This section is descriptive only. Normative behavior is described in Sections 8 and 9. /----- // STUN \ | Server | \\ // \-----/ -------------- Public Internet ................| NAT 2 |....................... -------------- -------------- Private NET 2 ................| NAT 1 |....................... -------------- /----- // STUN \ | Client | \\ // Private NET 1 \-----/ Figure: STUN Configuration 8. Server Behavior The server behavior depends on whether the request is a Binding Request or a Shared Secret Request. 9. Client Behavior The behavior of the client is very straightforward. Its task is to discover the STUN server, obtain a shared secret, formulate the Binding Request, handle request reliability, and process the Binding Responses. 10.Use Case -------- | Test | | I | -------- | | V /\ / N / \ Y / \ Y -------- UDP <-------/Resp\--------->/ IP \------------->| Test | Blocked \ ? / \Same/ | II | \ / \? / -------- \/ \/ | | N | | V V / -------- Sym. N / | Test | UDP <---/Resp | II | Firewall \ ? / -------- \ / | \/ V |Y /\ /\ | Symmetric N / \ -------- N / \ V NAT <--- / IP \<-----| Test |<--- /Resp\ Open \Same/ | I | \ ? / Internet \? / -------- \ / \/ \/ | |Y | | | V | Full | Cone V / -------- / \ Y | Test |------>/Resp\---->Restricted | III | \ ? / -------- \ / \/ |N | Port ------>Restricted Figure 2: Flow for type discovery process 11.1 Message Header All STUN messages consist of a 20 byte header: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | STUN Message Type | Message Length | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Transaction ID - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The Message Types can take on the following values: 0x0001 : Binding Request 0x0101 : Binding Response 0x0111 : Binding Error Response 0x0002 : Shared Secret Request 0x0102 : Shared Secret Response 0x0112 : Shared Secret Error Response 11.2 Message Attributes After the header are 0 or more attributes. Each attribute is TLV encoded, with a 16 bit type, 16 bit length, and variable value: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Type | Length | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | Value .... - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The following types are defined: 0x0001: MAPPED-ADDRESS 0x0002: RESPONSE-ADDRESS 0x0003: CHANGE-REQUEST 0x0004: SOURCE-ADDRESS 0x0005: CHANGED-ADDRESS 0x0006: USERNAME 0x0007: PASSWORD 0x0008: MESSAGE-INTEGRITY 0x0009: ERROR-CODE 0x000a: UNKNOWN-ATTRIBUTES 0x000b: REFLECTED-FROM Binding Shared Shared Shared Binding Binding Error Secret Secret Secret Att. Req. Resp. Resp. Req. Resp. Error Resp. _____________________________________________________________________ MAPPED-ADDRESS N/A M N/A N/A N/A N/A RESPONSE-ADDRESS O N/A N/A N/A N/A N/A CHANGE-REQUEST O N/A N/A N/A N/A N/A SOURCE-ADDRESS N/A M N/A N/A N/A N/A CHANGED-ADDRESS N/A M N/A N/A N/A N/A USERNAME O N/A N/A N/A M N/A PASSWORD N/A N/A N/A N/A M N/A MESSAGE-INTEGRITY O O N/A N/A N/A N/A ERROR-CODE N/A N/A M N/A N/A M UNKNOWN-ATTRIBUTES N/A N/A C N/A N/A C REFLECTED-FROM N/A C N/A N/A N/A N/A ====================================================================== 往下的章節大都講Message、Attribute,也可以看看唷! ※RFC 3489 http://www.faqs.org/rfcs/rfc3498.html 發表人 - kj68215 於 2004/08/09 22:14:51
------
-----------------------
請多多指教啦!!^^
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#11 引用回覆 回覆 發表時間:2004-08-09 21:56:12 IP:220.132.xxx.xxx 未訂閱
順便上stun的偵測程式吧,這是小弟前幾天找到的! 試試看~    ※Windows版本的STUN程式下載(Server+Client),這網站還有Linux以及win32模式的版本唷,但是小弟找不到source code!
------
-----------------------
請多多指教啦!!^^
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#12 引用回覆 回覆 發表時間:2004-08-09 23:16:03 IP:61.64.xxx.xxx 未訂閱
http://www.iptel.org/ser/doc/seruser/seruser.html#AEN985 http://www.iptel.org/ser/doc/seruser/seruser.html http://www.vovida.org/applications/downloads/stun/ http://www.ietf.org/rfc/rfc3489.txt http://www.vovida.org/protocols/downloads/sip/index.html
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#13 引用回覆 回覆 發表時間:2004-08-10 09:47:53 IP:61.221.xxx.xxx 未訂閱
kj68215 兄 你好 為何給我分數類 你有找到你要的東西了嗎? >>>>>>>>>>>>>>>>>>>>>>>>>> 回顧舊題
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#14 引用回覆 回覆 發表時間:2004-08-10 23:28:13 IP:220.136.xxx.xxx 未訂閱
conundrum兄, 小弟認為不一定針對題目,答對了才給分! 或許提供了有用的資訊(雖然只是相關),我覺得這分數給你也是理所當然! 不瞞你說,小弟最近是有那麼一些靈感了,但是實際上還是要實作看看. 若成功了,或許哪天小弟有空時會把我這些研究心得發表在 > 發表人 -
------
-----------------------
請多多指教啦!!^^
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#15 引用回覆 回覆 發表時間:2004-08-11 01:00:25 IP:61.64.xxx.xxx 未訂閱
kj68215 兄 你好    我會這麼問 不是在意分數 是覺得以點遺憾    1 你在很久以前就有問類似網路問題 2 你給分數等於某 階段 結案 讓我是否你想的部份與我的差異    (討論的本特性=妳的靈感 當然這不是強制的)    前人種樹後人涼 妳的分享 我想大家都會很期待把 感恩喔    哈哈
JerryKuo
版主


發表:42
回覆:571
積分:322
註冊:2003-03-10

發送簡訊給我
#16 引用回覆 回覆 發表時間:2004-09-14 11:21:29 IP:220.135.xxx.xxx 未訂閱
kj68215你好: 請問一下你的這些圖是自己畫的嗎?或是有可以參考的文件? 畫得比RFC好很多。
kj68215
初階會員


發表:47
回覆:91
積分:27
註冊:2003-08-09

發送簡訊給我
#17 引用回覆 回覆 發表時間:2004-09-16 18:21:28 IP:61.56.xxx.xxx 未訂閱
引言: kj68215你好: 請問一下你的這些圖是自己畫的嗎?或是有可以參考的文件? 畫得比RFC好很多。
小弟是有找到相關的文章,不過就如之前所說的,很片段! 而以上所說的,是小弟整理出的重點,但實際要真的瞭解,還是得看rfc文件! 老實說,小弟也沒有把整偏重頭看到尾,只抓重點的部分來看,有興趣的話,可以先看看 > ----------------------- 請多多指教啦!!^^
------
-----------------------
請多多指教啦!!^^
系統時間:2024-05-09 6:38:46
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!