請問有什麼方法可以偵測NAT的類型呢? |
缺席
|
kj68215
初階會員 發表:47 回覆:91 積分:27 註冊:2003-08-09 發送簡訊給我 |
小弟想寫一個偵測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 發送簡訊給我 |
|
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
|
kj68215
初階會員 發表:47 回覆:91 積分:27 註冊:2003-08-09 發送簡訊給我 |
引言: 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 發送簡訊給我 |
【分享】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 發送簡訊給我 |
|
kj68215
初階會員 發表:47 回覆:91 積分:27 註冊:2003-08-09 發送簡訊給我 |
引言: 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 發送簡訊給我 |
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 發送簡訊給我 |
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 發送簡訊給我 |
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 發送簡訊給我 |
|
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
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 發送簡訊給我 |
|
kj68215
初階會員 發表:47 回覆:91 積分:27 註冊:2003-08-09 發送簡訊給我 |
|
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
|
JerryKuo
版主 發表:42 回覆:571 積分:322 註冊:2003-03-10 發送簡訊給我 |
|
kj68215
初階會員 發表:47 回覆:91 積分:27 註冊:2003-08-09 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |