Nat type detection

Source: Internet
Author: User

The stun client () sends a request to the stun server (404: 40), requesting the address mapped by NAT ):
       A. If no server reply is received, UDP is regarded as blocked by the firewall and cannot communicate. network type: blocked.
       B. receive a response from the server (if the address is a ing address or a source address). if the address is the same as the local address (the source address is returned ), the device is considered to have no NAT device (without Nat ing and conversion) and enters Step 1. Otherwise, the device is considered to have a NAT device and enters step 3.
   2. (No NAT device has been confirmed) the stun client sends a request to the stun server, requesting the server to reply the packet from another IP address and port (505: 50) to the client:
       A. if the server cannot receive a reply from another IP address, it is deemed that the packet is blocked by the front-end firewall. The network type is hierarchical Ric UDP firewall. (if there is no Nat, you can receive a reply in any way. Only one side is blocked by the firewall, and sometimes anti-virus software is blocked)

B. The client is considered to be in an open network. The network type is opened.
   3. The stun client (10:10) sends a request to the stun server (404: 40), requesting the server to send a request from another IP address and port (505: 50) reply to the client:

 A. The server cannot receive replies from other IP addresses (including IP addresses and ports). If the packets are blocked by the front-end NAT device, the server enters step 2.
Nat type, no matter which IP address or port can receive a reply)
       B. If yes, the NAT device type is full cone, that is, the network type is full cone Nat)
   4. The stun client (10:10) sends a request to another IP address (404: 40, port cannot be changed) of the stun server (505: 40, obtain the NAT ing address (20: 20, if not symmetric, The ing address should be returned), and compare it (compared with the ing address returned in step 1)
       A. If the addresses are not the same, the network type is Nat. (For symmetric type, a new port will be mapped when a request is sent at to a different IP address (505, the port remains unchanged), which is equivalent to generating a port at. The comparison is different)
       B. Restricted NAT (restricted). Proceed to Step 1 to confirm the type.
5. (restricted NAT device confirmed) stun client () sends a request to stun server (404: 40), requiring the server to send requests from other ports (41) with the same IP address (404) reply to the client:
       A. The server cannot receive a response from another port address. It is considered that the packet is blocked by the Front NAT device. The network type is port restricted cone Nat. (The port is changed. The port is restricted, which is equivalent to a (101) Apple who wants the right hand (40) to B (404), while B has a banana in the left hand (41, A only needs B's right-hand apple, and B gives a's left-hand banana. A certainly doesn't want it, which is equivalent to failing to receive a reply)
       B. The network type is restricted cone Nat. (the IP address is limited and there is no requirement on the port, as long as it is 404.

This IP address is enough, no matter which port is used)



Several types of NAT detection code:

Implementation: http://sourceforge.net/projects/stun/STUNT

[From: http://nutss.gforge.cis.cornell.edu/stunt.php?stunt (Simple Traversal of UDP through NATs and TCP too), which extends stun to include TCP functionality, is a lightweight protocol that allows applications running behind a NAT to determine external IP and port-binding properties,
Packet filtering rules and various timeouts associated with TCP connections through the nat. knowing these parameters allows applications to establish TCP sessions between two Nat 'ed hosts. as a result P2P and other applications can work through existing Nat
Infrastructure without sacrifle icing the benefits of TCP. Implementation: https://gforge.cis.cornell.edu/frs? Group_id = 15 xstunt

[From: http://www.cis.nctu.edu.tw /~ Gis87577/xdreaming/xstunt/index.html] xstunt is a C/C ++ library which implements "stunt #2" approach in "characterization and measurement of TCP traversal through NAT and firewils ". it provides programmers with a set of simple functions to create stunt connections
Through cooperating with a particle xstunt server implementation: http://www.cis.nctu.edu.tw /~ Gis87577/xdreaming/xstunt/index.html other materials: 1. characterization and measurement of TCP traversal through NATs and firewals (PDF ). 2. peer-to-peer communication protocol SS network address translators ").

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.