A method that can accurately guess NAT's shot Port

Source: Internet
Author: User
Copyright: This article is published by SkyMountain at http://blog.csdn.net/skymountain /. The author reserves all copyrights and must indicate the source for reprinting. Otherwise, it is deemed as infringement. Last night, I suddenly came up with a method that could accurately guess the NAT shot port. I am referring to the type of NAT that is sensitive to the target port. Such NAT is hard to penetrate before.

This method uses three new Sockets (that is, the new local port) to detect . Create three new sockets, each of which corresponds to a port that has never been used before. BIND. Then, in chronological order, the first socket is sent to the stun Server The second socket sends a data packet to the target server. , That is, the drilling action is executed, and the third socket is sent to the stun server again Data. All three actions will open a new shooting port on the server. . The interval between the three actions is very short, about Ms. In this way, we have reason to believe that the second socket The allocated ing port is likely to be between the first and second ing ports. That is, port2> port2 <port3 at the same time in port1. The most likely is:
Port2 = (port1 + port3)/2

If port3 <port1, or port1 and por are detected on the serverThe gap between t3 is too large, so it is likely that the port number on NAT has started to score againSo the client should repeat the process. Repeated several timesThe chances of success are much higher.

An exception is that the port maintains NAT, that is, when a NAT port is assigned, Try to make the new port number consistent with the Intranet port number. However, this situation is easy to identify.The server simply compares the client's intranet port and ing port.. If this type of NAT is found, the above formula must be modified:
Port2 = Intranet Port Number of the second socket

Of course, no matter what the method of port speculation is, there is still no 100% connection rate between users in the intranet. But you can guess the port method.To improve the cross-NAT connection rate, thus reducing the burden on the data transfer server.

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.