Intranet NAT (Network Address Translation) layer number determination method and device and electronic equipment

Send a detection message to the public network NAT equipment through the public network server, and use the difference in the response of the detection packet to determine the number of NAT layers in the network, solve the problem of accurately determining the number of NAT layers in the existing technology, and improve the P2P communication. Success rate.

CN119363701APending Publication Date: 2025-01-24ZHEJIANG UNIVIEW TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310915514.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-07-24
Publication Date
2025-01-24

AI Technical Summary

Technical Problem

When determining the number of intranet NAT layers, it is difficult to effectively deal with secure types of public network NAT devices, resulting in the inability to accurately determine the number of intranet NAT layers, affecting the success rate of P2P communication.

Method used

Actively launch a set of detection packets that can be reached and unable to reach the public network NAT devices through the public network server. The current survival time in the detection packet is updated and adjusted until the detection packet responses to differently, and the inner network is determined NAT layer number.

Benefits of technology

This method can work effectively in different types of public network NAT devices (including security and non -security types), improve the accuracy and applicability of the number of NAT layers in the number of NAT layers, and enhance the success rate of P2P communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119363701A_ABST
    Figure CN119363701A_ABST
Patent Text Reader

Abstract

The invention provides an intranet NAT layer number determination method and device and electronic equipment, and relates to the technical field of communication, and the method comprises the steps: receiving a request message sent by public network NAT equipment; the request message comprises an IP address and a first port number of the public network NAT device; respectively sending a detection message for the IP address and the first port number and a detection message for the IP address and the second port number to public network NAT (Network Address Translation) equipment; the detection message comprises the current survival time; the second port number is an unreachable port number; and under the condition that the response corresponding to each detection message is determined to be the same, updating the current survival time, and respectively sending new detection messages aiming at the IP address and the first port number and the IP address and the second port number to the public network NAT equipment until the current survival time is updated under the condition that the response corresponding to each new detection message is determined to be different. And determining the number of NAT layers of the intranet based on the updated current survival time. According to the invention, the applicability of the method for determining the number of NAT layers of the intranet is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a method, device and electronic device for determining the number of NAT layers in an intranet. Background Art

[0002] Network Address Translation (NAT) enables multiple devices in the intranet to use the same Internet Protocol (IP) address to connect to the Internet by mapping different private network addresses to different port numbers of the same public network address, thus solving the problem of exhaustion of Internet Protocol address resources. In peer-to-peer (P2P) communication technology, the first intranet device may access the public network server after passing through multiple layers of NAT devices, and the public network server then passes through multiple layers of NAT devices to the second intranet device. In order to improve the success rate of P2P communication, it is usually necessary to carry a time to live (TTL) value in the hole punching request so that the set time to live value TTL can ensure that the hole punching request cannot be sent to the NAT on the second intranet device. Therefore, it is necessary to know the number of intranet NAT layers on the first intranet device to set an accurate time to live value TTL.

[0003] In the related technology, the public network server initiates a detection message for the unreachable port of the public network NAT device. Based on the routing tracking principle, when it is determined that the response returned when TTL=n is a timeout response, and the response returned when TTL=n+1 is a port unreachable response, the public network server determines that the detection message has reached the public network NAT device, and thus determines the number of internal network NAT layers based on TTL=n+1.

[0004] However, for a security-type public NAT device, when receiving a detection message, no matter whether TTL-1 is equal to zero or not, no response is returned to the public server. In this way, since the public server does not receive the response to TTL=n and TTL=n+1 returned by the public NAT device within the preset timeout period, it is considered that the responses to TTL=n and TTL=n+1 are both timeout responses. Therefore, it is impossible to determine whether the detection message has reached the public NAT device, and it is also impossible to determine the number of intranet NAT layers, resulting in poor applicability of the above-mentioned method for determining the number of intranet NAT layers. Summary of the invention

[0005] In view of the problems existing in the prior art, the embodiments of the present invention provide a method, device and electronic device for determining the number of NAT layers in an intranet.

[0006] The present invention provides a method for determining the number of NAT layers in an intranet, which is applied to a public network server. The method comprises:

[0007] Receive a request message sent by a public network NAT device; the request message includes the IP address and the first port number of the public network NAT device; the request message is a message sent by an intranet device through the intranet NAT device;

[0008] Sending detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through a routing device; the detection message includes a current lifetime; the second port number is an unreachable port number of the public network NAT device;

[0009] When it is determined that the responses corresponding to each of the detection messages are the same, the current lifetime is updated, and new detection messages for the IP address and the first port number, and for the IP address and the second port number are respectively sent to the public network NAT device through the routing device, until it is determined that the responses corresponding to each of the new detection messages are different, and the number of intranet NAT layers is determined based on the updated current lifetime; the new detection message includes the updated current lifetime.

[0010] The present invention also provides a method for determining the number of NAT layers in an intranet, which is applied to a public network NAT device, and the method comprises:

[0011] Sending a request message to a public network server; the request message includes the IP address and the first port number of the public network NAT device;

[0012] Respectively receiving the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through the routing device; the detection message includes the current lifetime; the second port number is an unreachable port number;

[0013] Respectively receive new detection messages for the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through the routing device; the new detection message includes the updated current lifetime; the new detection message is sent by the public network server after updating the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same; the updated current lifetime is used to instruct the public network server to determine the number of intranet NAT layers based on the updated current lifetime when it is determined that the responses corresponding to each of the new detection messages are different.

[0014] The present invention also provides a device for determining the number of NAT layers in an intranet, comprising:

[0015] A first receiving unit, configured to receive a request message sent by a public network NAT device; the request message includes an IP address and a first port number of the public network NAT device; the request message is a message sent by an intranet device through the intranet NAT device;

[0016] A first sending unit is used to send a detection message for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through a routing device; the detection message includes a current lifetime; the second port number is an unreachable port number of the public network NAT device;

[0017] A determination unit is used to update the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same, and send new detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through the routing device, until it is determined that the responses corresponding to each of the new detection messages are different, and the number of intranet NAT layers is determined based on the updated current lifetime; the new detection message includes the updated current lifetime.

[0018] The present invention also provides a device for determining the number of NAT layers in an intranet, comprising:

[0019] A second sending unit, used to send a request message to a public network server; the request message includes an IP address and a first port number of a public network NAT device;

[0020] A second receiving unit is used to receive the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, respectively, which are sent by the public network server through the routing device; the detection message includes the current survival time; the second port number is an unreachable port number;

[0021] The second receiving unit is also used to respectively receive the IP address and the first port number of the public network NAT device, and the new detection message for the IP address and the second port number of the public network NAT device, which are sent by the public network server through the routing device; the new detection message includes the updated current lifetime; the new detection message is sent by the public network server after updating the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same; the updated current lifetime is used to instruct the public network server to determine the number of intranet NAT layers based on the updated current lifetime when it is determined that the responses corresponding to each of the new detection messages are different.

[0022] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above methods for determining the number of NAT layers in an intranet is implemented.

[0023] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the method for determining the number of NAT layers in an intranet as described in any one of the above is implemented.

[0024] The present invention also provides a computer program product, including a computer program, and when the computer program is executed by a processor, the method for determining the number of NAT layers in an intranet as described above is implemented.

[0025] The present invention provides a method, device and electronic device for determining the number of intranet NAT layers. A public network server obtains the IP address and the first port number of the public network NAT device from a request message sent by the intranet device, and sends detection messages for the IP address and the first port number, and the IP address and the second port number to the public network NAT device through a routing device, respectively. The detection message includes the current lifetime, the first port number is a reachable port number, and the second port number is an unreachable port number. When it is determined that the responses corresponding to each detection message are the same, the current lifetime in the detection message is updated, and new detection messages for the IP address and the first port number, and the IP address and the second port number are continuously sent to the public network NAT device through the routing device until the responses corresponding to each new detection message are different, then the detection is stopped, and the number of intranet NAT layers is determined based on the updated current lifetime in the new detection message. It can be seen that the present invention actively initiates a group of detection messages for the reachable first port number and the unreachable second port number of the public network NAT device from the public network server. In this way, no matter whether the public network NAT device is a secure NAT device or an unsecure NAT device, based on multiple detections of a group of detection messages, it can be determined that the detection message has reached the public network NAT device when it is determined that the responses corresponding to the group of detection messages are different; in addition, since the updated current lifetime included in the detection message at this time can represent the total number of routing devices and public network NAT devices between the public network NAT device and the public network server, the number of intranet NAT layers between the intranet device and the public network server can be determined based on the updated current lifetime, thereby improving the applicability of the method for determining the number of intranet NAT layers. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0027] Figure 1 It is a schematic diagram of the principle of the route tracking technology provided by the present invention;

[0028] Figure 2 This is one of the schematic diagrams for determining the number of NAT layers in the intranet in the related art;

[0029] Figure 3 This is the second schematic diagram of determining the number of NAT layers in the intranet in the related art;

[0030] Figure 4 This is one of the flow charts of the method for determining the number of NAT layers in an intranet provided by an embodiment of the present invention;

[0031] Figure 5 This is a second flow chart of a method for determining the number of NAT layers in an intranet provided by an embodiment of the present invention;

[0032] Figure 6 This is a third flow chart of a method for determining the number of NAT layers in an intranet provided by an embodiment of the present invention;

[0033] Figure 7 This is one of the schematic diagrams for determining the number of NAT layers in an intranet provided by an embodiment of the present invention;

[0034] Figure 8 This is the second schematic diagram of determining the number of NAT layers in an intranet provided by an embodiment of the present invention;

[0035] Fig. 9 This is one of the structural schematic diagrams of the device for determining the number of NAT layers in an intranet provided by an embodiment of the present invention;

[0036] Fig.10 This is a second structural diagram of the device for determining the number of NAT layers in an intranet provided by an embodiment of the present invention;

[0037] Fig.11 It is a schematic diagram of the physical structure of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0038] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0039] The principle of the route tracking technology is: the header of the IP data packet at the network layer has a TTL field, which indicates the maximum number of routing times allowed before the IP data packet is discarded by the router. Therefore, each time the IP data packet passes through a router, before forwarding the data to the next router, the TTL will be reduced by 1. If the TTL is not equal to 0 after being reduced by 1, the IP data packet will be forwarded to the next router; if the TTL is equal to 0 after being reduced by 1, the IP data packet will be discarded and an error message will be returned, including an ICMP timeout response; therefore, by setting different TTL lengths, the IP data packet can be detected multiple times in the network, and the IP information of each router on the link can be obtained according to the returned error information.

[0040] Figure 1 It is a schematic diagram of the principle of the routing tracking technology provided by the present invention, such as Figure 1 As shown, including source host A, router 01, router 02 and target host B, the specific routing tracking example process is as follows:

[0041] 1) Source host A sends a User Datagram Protocol (UDP) datagram with a port number greater than 30000 and TTL=1. After receiving the UDP datagram, the first-hop router 01 checks the destination IP address in the UDP datagram for forwarding. Before forwarding, it will reduce the TTL by 1. If it is determined that the TTL is equal to 0 after reduction by 1, the UDP datagram is discarded and an Internet Control Message Protocol (ICMP) timeout message is returned to the source host A. When receiving the ICMP timeout message returned by the first-hop router 01, the source host A can obtain the IP address of the first-hop router 01 from the ICMP timeout message.

[0042] 2) Since source host A has not received the ICMP port unreachable message, it continues to send new UDP datagrams. At this time, the TTL in the new UDP datagram is 2. After the first-hop router 01 receives the new UDP datagram, it checks the destination IP address in the new UDP datagram for forwarding. Before forwarding, it will reduce the TTL by 1. If it is determined that the TTL is not equal to 0 after reducing by 1, it will forward the new UDP datagram to the second-hop router 02. After the second-hop router 02 receives the new UDP datagram, it checks the destination IP address in the new UDP datagram for forwarding. Before forwarding, it will reduce the TTL by 1. If it is determined that the TTL is equal to 0 after reducing by 1, it will discard the UDP datagram and return an ICMP timeout message to the source host A. When the source host A receives the ICMP timeout message returned by the second-hop router 002, it can obtain the IP address of the second-hop router 02 from the ICMP timeout message.

[0043] 3) Since source host A has not received the ICMP port unreachable message, it continues to send new UDP datagrams. At this time, the TTL in the new UDP datagram is 3. According to the above steps 1) and 2), the new UDP datagram will be forwarded to the target host B. The target host B determines that the destination IP address in the new UDP datagram is its own IP address, so it continues to decapsulate and check the data part of the new UDP datagram. It finds that the port number is unreachable, so it returns the ICMP port unreachable message to the source host A. When the source host A receives the ICMP port unreachable message returned by the target host B, it confirms that the new UDP datagram has successfully reached the target host B, and the route tracking ends.

[0044] Based on the above-mentioned routing tracking principle, in the related technology, a detection message is usually initiated through a public network server to determine the number of NAT layers in the internal network.

[0045] Figure 2 This is one of the schematic diagrams for determining the number of NAT layers in the intranet in the related technology, such as Figure 2 As shown, the link includes a host, an intranet NAT1 device, an intranet NAT2 device, a public network NAT3 device, a routing device and a public network server. Both the intranet NAT device and the public network NAT device are non-secure NAT devices, and each NAT device can be a routing device with NAT function, that is, a router.

[0046] like Figure 2As shown, when the public network server initiates UDP detection message 1 with a port number greater than 30000 and TTL=1, UDP detection message 1 reaches the routing device first, and the routing device determines that TTL-1 is equal to 0, then returns an ICMP timeout message to the public network server; the public network server initiates UDP detection message 2 with TTL=2 again, and UDP detection message 2 with TTL=2 reaches the routing device first, and the routing device determines that TTL-1 is equal to 1, then sends UDP detection message 2 with TTL=1 to the public network NAT3 device, and the public network NAT3 device determines that TTL-1 is equal to 0, then returns an ICMP timeout message to the public network server; the public network server initiates UDP detection message 3 with TTL=3 again, and UDP detection message 3 with TTL=3 reaches the routing device first, and the routing device determines that TTL-1 is equal to 2, then sends UDP detection message 3 with TTL=2 is sent, and the public network NAT3 device determines that TTL-1 is equal to 1, and determines that the destination IP address in UDP detection message 3 with TTL=2 is the IP address of the public network NAT3 device, and then determines whether the destination port in UDP detection message 3 with TTL=2 is an unreachable port. When it is determined that the destination port in UDP detection message 3 with TTL=2 is an unreachable port, an ICMP port unreachable message is returned to the public network server. When the public network server receives the ICMP port unreachable message, it determines that the UDP detection message with TTL=3 has been successfully sent to the public network NAT3 device. At this time, since the TTL value carried in the UDP detection message with TTL=3 is 3, TTL-1 in the UDP detection message with TTL=3 can be determined as the number of inner NAT layers, that is, the number of inner NAT layers is 2.

[0047] Figure 3 This is the second schematic diagram of determining the number of NAT layers in the intranet in the related technology, such as Figure 3 As shown, the link includes a host, an intranet NAT1 device, an intranet NAT2 device, a public network NAT3 device, a routing device and a public network server. The intranet NAT devices are all non-secure NAT devices, the public network NAT devices are secure NAT devices, and each NAT device can be a routing device with NAT function, that is, a router.

[0048] like Figure 3As shown, when the public network server initiates UDP detection message 1 with a port number greater than 30000 and TTL=1, UDP detection message 1 reaches the routing device first, and the routing device determines that TTL-1 is equal to 0, then returns an ICMP timeout message to the public network server; the public network server initiates UDP detection message 2 with TTL=2 again, and UDP detection message 2 with TTL=2 reaches the routing device first, and the routing device determines that TTL-1 is equal to 1, then sends UDP detection message 2 with TTL=1 to the public network NAT3 device. Since the public network NAT3 device is a secure NAT device, for security reasons, the public network NAT3 device does not return an ICMP message to the public network server regardless of whether TTL-1 is equal to 0. The public network server does not receive any information about the timeout within the preset timeout period. 3. When the public network NAT3 device receives the response to UDP detection message 2 with TTL=2, it considers that UDP has timed out. Therefore, when the public network server initiates UDP detection message 3 with TTL=3 again, the public network NAT3 device still does not return the ICMP message to the public network server, resulting in the public network server not receiving the response to UDP detection message 3 with TTL=3 within the preset timeout period, and considers that UDP has timed out. In other words, when the public network NAT3 device is a secure NAT device, the public network server considers that UDP has timed out for both UDP detection message 2 with TTL=2 and UDP detection message 3 with TTL=3. As a result, it is impossible to determine whether UDP detection message 3 with TTL=3 has successfully reached the public network NAT3 device based on the two UDP timeouts, and it is also impossible to determine the number of NAT layers in the intranet.

[0049] Based on this, the present invention proposes a method for determining the number of intranet NAT layers, in which a group of detection messages for a reachable first port number and an unreachable second port number of a public network NAT device are actively initiated from a public network server. In this way, regardless of whether the public network NAT device is a secure NAT device or a non-secure NAT device, based on multiple detections of a group of detection messages, it is possible to determine that the detection message has reached the public network NAT device when it is determined that the responses corresponding to the group of detection messages are different; in addition, since the updated current lifetime included in the detection message at this time can represent the total number of routing devices and public network NAT devices between the public network NAT device and the public network server, the number of intranet NAT layers between the intranet device and the public network server can be determined based on the updated current lifetime, thereby improving the applicability of the method for determining the number of intranet NAT layers.

[0050] Combine the following Figure 4 The method for determining the number of NAT layers in an intranet of the present invention is described. The execution subject of the embodiment of the present invention can be a public network server, or a device for determining the number of NAT layers in an intranet set in the public network server, and the device for determining the number of NAT layers in an intranet can be implemented by software, hardware, or a combination of both.

[0051] Figure 4It is one of the flow diagrams of the method for determining the number of NAT layers in an intranet provided by an embodiment of the present invention, and is applied to a public network server, such as Figure 4 As shown, the method for determining the number of NAT layers in the intranet includes the following steps:

[0052] Step 401, receiving a request message sent by a public network NAT device; the request message includes the IP address and the first port number of the public network NAT device; the request message is a message sent by an intranet device through the intranet NAT device.

[0053] Among them, the intranet device can be a computer, mobile phone and other devices in the intranet, and at least one intranet NAT device, one public network NAT device and at least one routing device are arranged between the intranet device and the public network server in sequence; the request message can be a UDP request message; precisely because the public network server does not know the number of intranet NAT devices and the number of routing devices between the intranet device and the public network server, the method for determining the number of intranet NAT layers provided by the present invention is required to first determine the total number of routing devices and public network NAT devices, that is, first determine the number of external network NAT layers, and then determine the number of intranet NAT layers based on the number of external network NAT layers.

[0054] For example, taking an intranet NAT device and a routing device as examples, the initial request message sent from the intranet device includes the port number of the intranet device, the IP address of the intranet device, the IP address of the public network server and the port number of the public network server. When the initial request message passes through the intranet NAT device, the intranet NAT device changes the IP address of the intranet device in the initial request message to the IP address of the intranet NAT device, and changes the port number of the intranet device in the initial request message to the port number of the intranet NAT device, to obtain a changed request message; the intranet NAT device sends the changed request message to the public network NAT device, and the public network NAT device then changes the IP address of the intranet NAT device in the changed request message to the IP address of the public network NAT device, and changes the port number of the intranet NAT device in the changed request message to the first port number of the public network NAT device, to obtain a request message, and the public network NAT device sends the request message to the public network server, that is, the public network server receives the request message sent by the public network NAT device, and the request message includes the IP address of the public network NAT device and the first port number of the public network NAT device.

[0055] Step 402: Send detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through the routing device; the detection message includes the current lifetime; the second port number is the unreachable port number of the public network NAT device.

[0056] The second port number of the public network NAT device may be a random unreachable port number greater than 33000.

[0057] For example, when the public network server receives a request message sent by the public network NAT device, it parses the request message to obtain the IP address of the public network NAT device and the first port number of the public network NAT device. Since the first port number changed by the public network NAT device must be a reachable port number, the first port number parsed by the public network server from the message request is the reachable port number, and the current lifetime is set, and the current lifetime is carried in the detection message. A group of detection messages are sent to the public network NAT device based on the IP address and the reachable first port number of the public network NAT device, and the IP address and the unreachable second port number of the public network NAT device, respectively. One detection message is for the reachable first port number of the public network NAT device, and the other detection message is for the unreachable second port number of the public network NAT device.

[0058] Step 403: When it is determined that the responses corresponding to each of the detection messages are the same, the current lifetime is updated, and new detection messages for the IP address and the first port number, and for the IP address and the second port number are respectively sent to the public network NAT device through the routing device, until it is determined that the responses corresponding to each of the new detection messages are different, and the number of intranet NAT layers is determined based on the updated current lifetime; the new detection message includes the updated current lifetime.

[0059] For example, after the public network server sends a group of TTL=n detection messages to the public network NAT device based on the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, the group of detection messages first passes through the routing device. The routing device decides whether to forward the group of detection messages or return a timeout response corresponding to each detection message in the group of detection messages to the public network server based on whether the TTL in the group of detection messages is equal to 0 after being subtracted by 1. After the forwarding, the other routing device or the public network NAT device to which the detection message arrives processes the received detection message in a similar way to the routing device processing the received detection message.

[0060] When the public network server determines that the responses corresponding to each detection message are the same and are all timeout responses, it is considered that the group of detection messages has not successfully reached the public network NAT device. At this time, the public network server sends a group of new detection messages with TTL=n+1 to the public network NAT device based on the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device. The public network server continues to decide whether to forward the group of new detection messages or return the timeout response corresponding to each detection message in the group of new detection messages to the public network server based on whether the TTL in the group of new detection messages is equal to 0 after being subtracted by 1. This cycle is repeated until it is determined that the responses corresponding to each new detection message are different. The public network server believes that the group of new detection messages has successfully reached the public network NAT device. At this time, the detection is stopped. The value of TTL in the detection message sent last time minus 1 is the number of external network NAT layers. The number of external network NAT layers includes the sum of the number of public network NAT devices and the number of routing devices. Therefore, the number of internal network NAT layers can be determined based on the number of external network NAT layers and the total number of devices between the internal network device and the public network server.

[0061] The present invention provides a method for determining the number of intranet NAT layers. A public network server obtains the IP address and the first port number of the public network NAT device from a request message sent by an intranet device, and sends detection messages for the IP address and the first port number, and the IP address and the second port number to the public network NAT device through a routing device, respectively. The detection message includes the current lifetime, the first port number is a reachable port number, and the second port number is an unreachable port number. When it is determined that the responses corresponding to each detection message are the same, the current lifetime in the detection message is updated, and new detection messages for the IP address and the first port number, and the IP address and the second port number are continuously sent to the public network NAT device through the routing device until the responses corresponding to each new detection message are different, then the detection is stopped, and the number of intranet NAT layers is determined based on the updated current lifetime in the new detection message. It can be seen that the present invention actively initiates a group of detection messages from the public network server to the reachable first port number and the unreachable second port number of the public network NAT device. In this way, no matter whether the public network NAT device is a secure NAT device or an unsecure NAT device, based on multiple detections of a group of detection messages, it is possible to determine that the detection message has reached the public network NAT device when it is determined that the responses corresponding to the group of detection messages are different; in addition, since the updated current lifetime included in the detection message at this time can represent the total number of routing devices and public network NAT devices between the public network NAT device and the public network server, the number of intranet NAT layers between the intranet device and the public network server can be determined based on the updated current lifetime, thereby improving the applicability of the method for determining the number of intranet NAT layers.

[0062] In one embodiment, the request message also includes a target lifetime; the target lifetime is related to a preset lifetime and a number of devices; the number of devices is the total number of all devices between the intranet device and the public network server; the number of NAT layers is determined based on the updated current lifetime in the above step 403, which can be specifically implemented by the following steps:

[0063] The difference between the preset survival time and the target survival time is determined as the first survival time; the first survival time is used to represent the total number of all devices between the intranet device and the public network server; the difference between the first survival time and the updated current survival time minus 1 is determined as the number of intranet NAT layers.

[0064] The preset lifetime can be determined based on the operating system type of the intranet device, and is usually a default value determined based on the operating system type. For example, for an intranet device with a Windows operating system, the preset lifetime can be set to 64; for an intranet device with a Linux operating system, the preset lifetime can be set to 128. Of course, the preset lifetime can also be other values, as long as it ensures that the request message can be successfully sent from the intranet device to the public network server.

[0065] For example, the initial request message sent by the intranet device to the public network server includes a preset survival time. The initial request message reaches the public network server after passing through the intranet NAT device, the public network NAT device and the routing device. Based on the routing tracking principle, the preset survival time is reduced by 1 each time a routing device is passed. Therefore, when the initial request message including the preset survival time reaches the public network server, the target survival time included in the request message reaching the public network server is the value obtained by continuously reducing the preset survival time by 1. The intranet survival time can be determined based on the difference between the preset survival time and the target survival time in the request message reaching the public network server. The total number of all devices between the network device and the public network server, the total number of all devices includes the sum of the number of internal network NAT devices, the number of public network NAT devices and the number of routing devices; the total number of all devices is taken as the first survival time, and when it is determined that the responses corresponding to each new detection message are different, the public network server can determine the number of external network NAT layers based on the TTL value in the detection message sent last time minus 1, the number of external network NAT layers includes the sum of the number of public network NAT devices and the number of routing devices, so that the number of internal network NAT layers can be obtained by subtracting the number of external network NAT layers from the first survival time.

[0066] In this embodiment, the total number of all devices between the intranet device and the public network server can be determined based on the preset lifetime and the target lifetime in the request message, and the number of external NAT layers can be obtained based on the updated current lifetime minus 1. Finally, the number of intranet NAT layers can be obtained based on the difference between the total number of all devices and the number of external network NAT layers, thereby achieving accurate determination of the number of intranet NAT layers.

[0067] In one embodiment, determining in the above step 403 that the responses corresponding to the respective detection messages are all timeout responses can be specifically implemented in the following manner:

[0068] In a first manner, when a timeout response message corresponding to each of the detection messages is received, it is determined that the responses corresponding to each of the detection messages are the same.

[0069] For example, for any routing device, when the routing device determines that the TTL carried in the received probe message corresponding to the first port number is equal to 0 after minus 1, the routing device will return a timeout response of the probe message corresponding to the first port number to the public network server; when the routing device determines that the TTL carried in the received probe message corresponding to the second port number is equal to 0 after minus 1, the routing device will return a timeout response of the probe message corresponding to the second port number to the public network server, so that when the public network server receives the timeout response of the probe message corresponding to the first port number and the timeout response of the probe message corresponding to the second port number, it determines that the responses corresponding to each probe message are the same, that is, they are all timeout responses.

[0070] For the public network NAT device, when the public network NAT device is a non-secure NAT device, when the non-secure NAT device determines that the TTL carried in the received probe message corresponding to the first port number is equal to 0 after minus 1, it will return an ICMP timeout response of the probe message corresponding to the first port number to the public network server; when the non-secure NAT device determines that the TTL carried in the received probe message corresponding to the second port number is equal to 0 after minus 1, it will return an ICMP timeout response of the probe message corresponding to the second port number to the public network server, so that when the public network server receives the timeout response of the probe message corresponding to the first port number and the timeout response of the probe message corresponding to the second port number, it determines that the responses corresponding to each probe message are the same, that is, they are all timeout responses.

[0071] In the second manner, when no response message corresponding to each of the detection messages is received within a preset timeout period, it is determined that the responses corresponding to each of the detection messages are the same.

[0072] The preset timeout period may be set based on demand, for example, the preset timeout period may be 500 milliseconds.

[0073] For example, for a public network NAT device, when the public network NAT device is a secure NAT device, for the sake of security, when the secure NAT device receives a detection message corresponding to a first port number, regardless of whether the TTL of the detection message corresponding to the first port number is equal to 0 after being subtracted by 1, the ICMP message of the detection message corresponding to the first port number will not be returned to the public network server. When the public network server does not receive a response to the detection message corresponding to the first port number within a preset timeout period, it determines that the response to the detection message corresponding to the first port number is a UDP timeout. Similarly, when the secure NAT device receives a second port number, the secure NAT device will return an ICMP message of the detection message corresponding to the first port number to the public network server. When a probe message corresponding to the second port number is received, no matter whether the TTL of the probe message corresponding to the second port number is equal to 0 after minus 1, the ICMP message of the probe message corresponding to the second port number will not be returned to the public network server. When the public network server does not receive a response to the probe message corresponding to the second port number within the preset timeout period, it determines that the response to the probe message corresponding to the second port number is a UDP timeout. When the public network server considers that the UDP timeout of the probe message corresponding to the first port number and the UDP timeout of the probe message corresponding to the second port number are

[0074] In this embodiment, for different devices, the public network server determines that the responses corresponding to the respective detection messages are the same in different ways, which has high flexibility.

[0075] In one embodiment, determining that the responses corresponding to the respective detection messages are different can be specifically implemented in the following manner:

[0076] In a first manner, when a timeout response message of a probe message corresponding to the first port number is received and a port unreachable response message of a probe message corresponding to the second port number is received, it is determined that the responses corresponding to the probe messages are different.

[0077] For example, when the public network NAT device is a non-secure NAT device, when the non-secure NAT device determines that the TTL carried in the received detection message corresponding to the first port number is not equal to 0 after being subtracted by 1, the non-secure NAT device determines the IP address of the intranet NAT device that needs to forward the detection message based on the mapping relationship between the IP address of the non-secure NAT device and the IP address of the intranet NAT device stored in the non-secure NAT device, and sends a detection message with TTL minus 1 to the intranet NAT device based on the IP address of the intranet NAT device. When the intranet NAT device receives the detection message with TTL minus 1, when it determines that TTL minus two is equal to 0, it returns an ICMP timeout message of the detection message corresponding to the first port number to the public network server. The ICMP timeout message is a timeout response message.

[0078] When the non-secure NAT device determines that the TTL carried in the received detection message corresponding to the second port number is not equal to 0 after deducting 1, it determines whether the destination IP address carried in the detection message corresponding to the second port number is the IP address of the non-secure NAT device. When it determines that the destination IP address carried in the detection message corresponding to the second port number is the IP address of the non-secure NAT device, it determines whether the second port number is an unreachable port number. When it determines that the second port number is an unreachable port number, the non-secure NAT device returns an ICMP port unreachable message to the public network server, and the ICMP port unreachable message is a port unreachable response. Therefore, the public network server receives a timeout response message for the detection message corresponding to the first port number, and receives a port unreachable response message for the detection message corresponding to the second port number, so that it can be determined that the responses of each detection message are different.

[0079] The second manner is to determine that the responses corresponding to the respective probe messages are different when a timeout response message of the probe message corresponding to the first port number is received and a response message of the probe message corresponding to the second port number is not received.

[0080] For example, when the public network NAT device is a security NAT device, for security reasons, the security NAT device does not return an ICMP message to the public network server regardless of whether the TTL carried in the received detection message corresponding to the first port number minus 1 is equal to 0, that is, it does not return a response message to the public network server. However, since the first port number is a reachable port number, when the security NAT device determines that the TTL carried in the detection message corresponding to the first port number minus 1 is not equal to 0, it needs to determine the IP address of the intranet NAT device that needs to forward the detection message based on the stored mapping relationship between the IP address of the security NAT device and the IP address of the intranet NAT device, and send a detection message with TTL minus 1 to the intranet NAT device based on the IP address of the intranet NAT device. When the intranet NAT device receives the detection message with TTL minus 1, when it determines that TTL minus two is equal to 0, it returns the ICMP timeout message of the detection message corresponding to the first port number to the public network server, that is, returns a timeout response message.

[0081] When the public network NAT device is a secure NAT device, for security reasons, the secure NAT device does not return an ICMP message to the public network server regardless of whether the TTL carried in the received detection message corresponding to the second port number is equal to 0 after deducting 1. However, since the second port number is an unreachable port number, the secure NAT device does not forward the detection message to the intranet NAT device when it determines that the TTL carried in the detection message corresponding to the second port number is not equal to 0 after deducting 1. Therefore, when the public network server does not receive a response to the detection message corresponding to the second port number within a preset timeout period, it considers that the response to the detection message corresponding to the second port number is a UDP timeout. Since the public network server determines that the timeout response to the detection message corresponding to the first port number is returned by the secure NAT device, and the timeout response to the detection message corresponding to the second port number is determined when the public network server does not receive a response to the detection message corresponding to the second port number within the preset timeout period, it can be determined that the responses of each detection message are different.

[0082] In this embodiment, for different devices, the public network server determines the responses corresponding to each detection message in different ways, which has high flexibility.

[0083] Combine the following Figure 5 and Figure 6 The method for determining the number of NAT layers in an intranet of the present invention is described. The execution subject of the embodiment of the present invention may be a public network NAT device, which may be a router with NAT function, or an intranet NAT layer determination device arranged in the public network NAT device, which may be implemented by software, hardware or a combination of the two.

[0084] Figure 5 FIG. 2 is a flow chart of a method for determining the number of NAT layers in an intranet provided by an embodiment of the present invention, and is applied to a public network NAT device, such as Figure 5 As shown, the method for determining the number of NAT layers in the intranet includes the following steps:

[0085] Step 501: Send a request message to a public network server; the request message includes the IP address and the first port number of the public network NAT device.

[0086] Step 502: Receive detection messages for the IP address and first port number of the public network NAT device, and the IP address and second port number of the public network NAT device, respectively, sent by the public network server through the routing device; the detection message includes the current lifetime; the second port number is an unreachable port number.

[0087] Step 503, respectively receive new detection messages for the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through the routing device; the new detection message includes the updated current lifetime; the new detection message is sent by the public network server after updating the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same; the updated current lifetime is used to instruct the public network server to determine the number of intranet NAT layers based on the updated current lifetime when it is determined that the responses corresponding to each of the new detection messages are different.

[0088] The present invention provides a method for determining the number of intranet NAT layers. A public network server obtains the IP address and the first port number of the public network NAT device from a request message sent by an intranet device, and sends detection messages for the IP address and the first port number, and the IP address and the second port number to the public network NAT device through a routing device, respectively. The detection message includes the current lifetime, the first port number is a reachable port number, and the second port number is an unreachable port number. When it is determined that the responses corresponding to each detection message are the same, the current lifetime in the detection message is updated, and new detection messages for the IP address and the first port number, and the IP address and the second port number are continuously sent to the public network NAT device through the routing device until the responses corresponding to each new detection message are different, then the detection is stopped, and the number of intranet NAT layers is determined based on the updated current lifetime in the new detection message. It can be seen that the present invention actively initiates a group of detection messages for the reachable first port number and the unreachable second port number of the public network NAT device from the public network server. In this way, no matter whether the public network NAT device is a secure NAT device or an unsecure NAT device, based on multiple detections of a group of detection messages, it can be determined that the detection message has reached the public network NAT device when it is determined that the responses corresponding to the group of detection messages are different; in addition, since the updated current lifetime included in the detection message at this time can represent the total number of routing devices and public network NAT devices between the public network NAT device and the public network server, the number of intranet NAT layers between the intranet device and the public network server can be determined based on the updated current lifetime, thereby improving the applicability of the method for determining the number of intranet NAT layers.

[0089] In one embodiment, Figure 6 FIG. 3 is a flow chart of a method for determining the number of NAT layers in an intranet provided by an embodiment of the present invention. Figure 6 As shown, before step 503, the method for determining the number of NAT layers in the intranet further includes the following steps:

[0090] Step 504: When the public network NAT device is a non-secure NAT device, when it is determined that the current lifetime minus one is not equal to zero and the destination IP address in the detection message is the IP address of the public network NAT device, a port number unreachable response message for the second port number is sent to the public network server through the routing device, and a third request message for the first port number is sent to the intranet NAT device; the third request message includes a second lifetime; the second lifetime is the current lifetime minus two.

[0091] Step 505: Receive a timeout response message for the first port number sent by the intranet NAT device when it is determined that the second lifetime minus one is equal to zero.

[0092] Step 506: Send a timeout response message for the first port number to the public network server through the routing device.

[0093] It should be noted that, when the public network NAT device is a secure NAT device, when it is determined that the current lifetime minus one is not equal to zero and the destination IP address in the detection message is the IP address of the public network NAT device, it is prohibited to send a port number unreachable response message for the second port number to the public network server through the routing device, and send a third request message for the first port number to the intranet NAT device; the third request message includes the second lifetime; the second lifetime is the current lifetime minus two; receive the timeout response message for the first port number sent by the intranet NAT device when it is determined that the second lifetime minus one is equal to zero; and send a timeout response message for the first port number to the public network server through the routing device. In this way, the public network server receives a timeout response message for the first port number, but since the public network server does not receive any response message for the second port number, the public network server considers that the response to the second port number is a timeout response, but the method for determining the timeout response to the first port number and the timeout response to the second port number are not the same. Therefore, the public network server can determine that the response to the detection message corresponding to the first port number and the response to the detection message corresponding to the second port number are different.

[0094] In one embodiment, if Figure 6 As shown, before step 503, the method for determining the number of NAT layers in the intranet further includes the following steps:

[0095] Step 507: When the public network NAT device is a non-secure NAT device, when it is determined that the current lifetime minus one is equal to zero, a timeout response message for the first port number and a timeout response message for the second port number are sent to the public network server through the routing device.

[0096] It should be noted that when the public network NAT device is a secure NAT device, when it is determined that the current lifetime minus one is equal to zero, it is prohibited to send a timeout response message for the first port number and a timeout response message for the second port number to the public network server through the routing device respectively.

[0097] It should be noted that the specific implementation methods and technical effects of the public network NAT device side can refer to the corresponding specific descriptions in the various embodiments of the public network server side, and the present invention will not be repeated here.

[0098] Figure 7 FIG. 1 is one of the schematic diagrams for determining the number of NAT layers in an intranet provided by an embodiment of the present invention, such as Figure 7 As shown, the link includes an intranet device, an intranet NAT1 device, an intranet NAT2 device, a public network NAT3 device, a routing device 1 and a public network server. The intranet NAT device and the public network NAT device are both non-secure NAT devices. Each NAT device can be a routing device with NAT function. Assume that the second port number of the public network NAT device is port2, and port2 can be an unreachable port with a port number greater than 33000. The request message sent by the intranet device received by the public network server includes the first port number of the public network NAT device as port1, the IP address as IP, and the target lifetime as 60. If the preset lifetime is 64, the first lifetime = 64-60 = 4; set the current lifetime TTL = n, taking n = 1 as an example. The process of the public network server performing multiple detections through a set of detection messages is as follows:

[0099] 1) The public network server simultaneously initiates UDP detection message a1 with IP+port1 and TTL=1, and UDP detection message b1 with IP+port2 and TTL=1. UDP detection message a1 and UDP detection message b1 reach routing device 1 first. Routing device 1 determines that TTL minus 1 is equal to 0, then routing device 1 returns the ICMP timeout message corresponding to UDP detection message a1 to the public network server, and returns the ICMP timeout message corresponding to UDP detection message b1 to the public network server.

[0100] 2) Since the responses to UDP detection messages a1 and b1 are both ICMP timeout, the public network server again initiates UDP detection message a2 with IP+port1 and TTL=2, and UDP detection message b2 with IP+port2 and TTL=2. UDP detection message a2 and UDP detection message b2 first reach routing device 1. Routing device 1 determines that TTL minus 1 is not equal to 0, so routing device 1 sends UDP detection message a2' with IP+port1 and TTL=1, and UDP detection message b2' with IP+port2 and TTL=1 to the public network NAT3 device. The public network NAT3 device determines that TTL minus 1 is equal to 0, so the public network NAT3 device returns the ICMP timeout message corresponding to UDP detection message a2 to the public network server through routing device 1, and returns the ICMP timeout message corresponding to UDP detection message b2 to the public network server through routing device 1.

[0101] 3) Since the responses to UDP detection messages a2 and b2 are both ICMP timeout, the public network server again initiates UDP detection message a3 with IP+port1 and TTL=3, and UDP detection message b3 with IP+port2 and TTL=3. UDP detection message a3 and UDP detection message b3 first reach routing device 1. Routing device 1 determines that TTL minus 1 is not equal to 0, so routing device 1 sends UDP detection message a3 with IP+port1 and TTL=2 to the public network NAT3 device. ', and the UDP detection message b3' of IP+port2 and TTL=2. The public network NAT3 device determines that the TTL minus 1 is not equal to 0, and the IP addresses in the UDP detection messages a3' and b3' are the IP addresses of the public network NAT3 device, port1 in the UDP detection message a3' is a reachable port, and port2 in the UDP detection message b3' is an unreachable port. Then the public network NAT3 device returns the ICMP port unreachable message corresponding to the UDP detection message b3 to the public network server through routing device 1.

[0102] Since port1 is a reachable port, the public network NAT3 device determines the IP address of the internal network NAT2 device based on the mapping relationship between the IP address of the public network NAT3 device and the IP address of the internal network NAT2 device. Assuming that the IP address of the internal network NAT2 device is IP1, the public network NAT3 device sends a UDP detection message a3'' with IP1+port1 and TTL=1 to the internal network NAT2 device. The internal network NAT2 device determines that the TTL minus 1 is equal to 0, and then sends the ICMP timeout message corresponding to the UDP detection message a3 to the public network server through the public network NAT3 device and routing device 1 in sequence. The public network server then receives the ICMP port unreachable message corresponding to UDP probe message b3, and the ICMP timeout message corresponding to UDP probe message a3, with different responses, thereby determining that UDP probe message a3 and UDP probe message b3 have successfully reached the public network NAT device, and stops detecting. The TTL in the last group of probe messages is 3, that is, the updated current lifetime is 3. The updated current lifetime minus 1 is equal to 2, which is determined as the number of external network NAT layers. Since the first lifetime represents the total number of all devices between the internal network device and the public network server, the first lifetime minus the number of external network NAT layers is equal to the number of internal network NAT layers, that is, 4-2=2, and the number of internal network NAT layers is 2.

[0103] The above Figure 7 The link shown in the figure introduces a method for determining the number of NAT layers in the internal network when the public network NAT device is a non-secure NAT device. By performing multiple detections through a group of detection messages, the number of NAT layers in the external network is first determined, and then the number of NAT layers in the internal network is determined based on the number of NAT layers in the external network, thereby improving the accuracy of determining the number of NAT layers in the internal network.

[0104] Figure 8 FIG. 2 is a second schematic diagram of determining the number of NAT layers in an intranet provided by an embodiment of the present invention. Figure 8 As shown, the link includes an intranet device, an intranet NAT1 device, an intranet NAT2 device, a public network NAT3 device, a routing device 1 and a public network server. The intranet NAT devices are all non-secure NAT devices, and the public network NAT devices are secure NAT devices. Each NAT device can be a routing device with NAT function, that is, a router. Assume that the second port number of the public network NAT device is port2, and port2 can be an unreachable port with a port number greater than 33000. The request message sent by the intranet device received by the public network server includes the first port number of the public network NAT device as port1, the IP address is IP, and the target lifetime is 60. If the preset lifetime is 64, then the first lifetime = 64-60 = 4; set the current lifetime TTL = n, taking n = 1 as an example. The process of the public network server performing multiple detections through a set of detection messages is as follows:

[0105] 1) The public network server simultaneously initiates UDP detection message a1 with IP+port1 and TTL=1, and UDP detection message b1 with IP+port2 and TTL=1. UDP detection message a1 and UDP detection message b1 reach routing device 1 first. Routing device 1 determines that TTL minus 1 is equal to 0, then routing device 1 returns the ICMP timeout message corresponding to UDP detection message a1 to the public network server, and returns the ICMP timeout message corresponding to UDP detection message b1 to the public network server.

[0106] 2) Since the responses to UDP detection messages a1 and b1 are both ICMP timeout, the public network server again initiates UDP detection message a2 with IP+port1 and TTL=2, and UDP detection message b2 with IP+port2 and TTL=2. UDP detection message a2 and UDP detection message b2 first reach routing device 1. Routing device 1 determines that TTL minus 1 is not equal to 0, so routing device 1 sends UDP detection message a2' with IP+port1 and TTL=1, and UDP detection message b2' with IP+port2 and TTL=1 to the public network NAT3 device. The T3 device is a secure NAT device. For security reasons, the public network NAT3 device will not return an ICMP timeout response message to the public network server regardless of whether TTL-1 is equal to 0. Therefore, when the public network NAT3 device determines that TTL minus 1 is equal to 0, it will not return the ICMP timeout message corresponding to UDP probe message a2 and the ICMP timeout message corresponding to UDP probe message b2 to the public network server. When the public network server does not receive a response to UDP probe message a2 and UDP probe message b2 within the preset timeout period, it considers that the response corresponding to UDP probe message a2 is UDP timeout, and the response corresponding to UDP probe message b2 is also UDP timeout.

[0107] 3) Since the responses to UDP detection messages a2 and b2 are both UDP timeout, the public network server again initiates UDP detection message a3 with IP+port1 and TTL=3, and UDP detection message b3 with IP+port2 and TTL=3. UDP detection message a3 and UDP detection message b3 first reach routing device 1. Routing device 1 determines that TTL minus 1 is not equal to 0, so routing device 1 sends UDP detection message a3' with IP+port1 and TTL=2, and UDP detection message b3' with IP+port2 and TTL=2 to public network NAT3 device. DP detection message b3', because the public network NAT3 device is a secure NAT device, when the public network NAT3 device determines that the TTL is not equal to 0 after minus 1, even if the IP address in the UDP detection message a3' and the UDP detection message b3' is the IP address of the public network NAT3 device, and port2 is an unreachable port, the public network NAT3 device does not send the ICMP port unreachable message corresponding to the UDP detection message b3' to the public network server. When the public network server does not receive a response to the UDP detection message b3 within the preset timeout period, it considers that the response corresponding to the UDP detection message b3 is a UDP timeout.

[0108] Since port1 is a reachable port, the public network NAT3 device determines the IP address of the internal network NAT2 device based on the mapping relationship between the IP address of the public network NAT3 device and the IP address of the internal network NAT2 device. Assuming that the IP address of the internal network NAT2 device is IP1, the public network NAT3 device sends a UDP detection message a3'' with IP1+port1 and TTL=1 to the internal network NAT2 device. The internal network NAT2 device determines that TTL minus 1 is equal to 0, and then sends the ICMP timeout message corresponding to the UDP detection message a3 to the public network server through the public network NAT3 device and routing device 1 in sequence.

[0109] The public network server determines that the response corresponding to UDP probe message b3 is UDP timeout, and the response corresponding to UDP probe message a3 is ICMP timeout, and the responses are different, thereby determining that UDP probe message a3 and UDP probe message b3 have successfully reached the public network NAT device, and stopping detection. The TTL in the last group of probe messages is 3, that is, the updated current lifetime is 3. The updated current lifetime minus 1 is equal to 2, which is determined as the number of external network NAT layers. Since the first lifetime represents the total number of all devices between the intranet device and the public network server, the first lifetime minus the number of external network NAT layers is equal to the number of internal network NAT layers, that is, 4-2=2, and the number of internal network NAT layers is 2.

[0110] The above Figure 8The link shown in the figure introduces a method for determining the number of NAT layers in the internal network when the public network NAT device is a secure NAT device. By performing multiple detections through a group of detection packets, the number of NAT layers in the external network is first determined, and then the number of NAT layers in the internal network is determined based on the number of NAT layers in the external network, thereby improving the accuracy of determining the number of NAT layers in the internal network.

[0111] The following is a description of the device for determining the number of Intranet NAT layers provided by the present invention. The device for determining the number of Intranet NAT layers described below and the method for determining the number of Intranet NAT layers described above can refer to each other.

[0112] Fig. 9 It is one of the structural diagrams of the device for determining the number of NAT layers in the intranet provided by the embodiment of the present invention, which is applied to the public network server, such as Fig. 9 As shown, the intranet NAT layer number determination device 900 includes a first receiving unit 901, a first sending unit 902 and a determination unit 903; wherein:

[0113] The first receiving unit 901 is used to receive a request message sent by a public network NAT device; the request message includes the IP address and the first port number of the public network NAT device; the request message is a message sent by an intranet device through the intranet NAT device.

[0114] The first sending unit 902 is used to send detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through a routing device; the detection message includes a current lifetime; the second port number is an unreachable port number of the public network NAT device.

[0115] The determination unit 903 is used to update the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same, and send new detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through the routing device, until it is determined that the responses corresponding to each of the new detection messages are different, and the number of intranet NAT layers is determined based on the updated current lifetime; the new detection message includes the updated current lifetime.

[0116] The present invention provides a device for determining the number of intranet NAT layers. A public network server obtains the IP address and the first port number of the public network NAT device from a request message sent by an intranet device, and sends detection messages for the IP address and the first port number, and the IP address and the second port number to the public network NAT device through a routing device, respectively. The detection message includes the current lifetime, the first port number is a reachable port number, and the second port number is an unreachable port number. When it is determined that the responses corresponding to each detection message are the same, the current lifetime in the detection message is updated, and new detection messages for the IP address and the first port number, and the IP address and the second port number are continuously sent to the public network NAT device through the routing device until the responses corresponding to each new detection message are different, then the detection is stopped, and the number of intranet NAT layers is determined based on the updated current lifetime in the new detection message. It can be seen that the present invention actively initiates a group of detection messages from the public network server to the reachable first port number and the unreachable second port number of the public network NAT device. In this way, no matter whether the public network NAT device is a secure NAT device or an unsecure NAT device, based on multiple detections of a group of detection messages, it is possible to determine that the detection message has reached the public network NAT device when it is determined that the responses corresponding to the group of detection messages are different; in addition, since the updated current lifetime included in the detection message at this time can represent the total number of routing devices and public network NAT devices between the public network NAT device and the public network server, the number of intranet NAT layers between the intranet device and the public network server can be determined based on the updated current lifetime, thereby improving the applicability of the method for determining the number of intranet NAT layers.

[0117] Based on any of the above embodiments, the request message also includes a target lifetime; the target lifetime is related to a preset lifetime and a number of devices; the number of devices is the total number of all devices between the intranet device and the public network server;

[0118] The determining unit 903 is specifically configured to:

[0119] The difference between the preset survival time and the target survival time is determined as a first survival time; the first survival time is used to represent the total number of all devices between the intranet device and the public network server;

[0120] The difference between the first lifetime and the updated current lifetime is subtracted by 1 to determine the number of NAT layers in the intranet.

[0121] Based on any of the foregoing embodiments, the determining unit 903 is specifically configured to:

[0122] Upon receiving a timeout response message corresponding to each of the detection messages, determining that the responses corresponding to each of the detection messages are the same; or;

[0123] When no response message corresponding to each of the detection messages is received within a preset timeout period, it is determined that the responses corresponding to each of the detection messages are the same.

[0124] Based on any of the foregoing embodiments, the determining unit 903 is specifically configured to:

[0125] In the case where a timeout response message of the detection message corresponding to the first port number is received and a port unreachable response message of the detection message corresponding to the second port number is received, determining that the responses corresponding to the detection messages are different; or,

[0126] When a timeout response message of the probe message corresponding to the first port number is received and a response message of the probe message corresponding to the second port number is not received, it is determined that the responses corresponding to the probe messages are different.

[0127] Fig.10 This is a second structural diagram of the device for determining the number of NAT layers in an intranet provided by an embodiment of the present invention, which is applied to a public network NAT device, such as Fig.10 As shown, the intranet NAT layer number determination device 1000 includes a second sending unit 1001 and a second receiving unit 1002; wherein:

[0128] The second sending unit 1001 is used to send a request message to the public network server; the request message includes the IP address and the first port number of the public network NAT device;

[0129] The second receiving unit 1002 is used to receive the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, respectively, which are sent by the public network server through the routing device; the detection message includes the current lifetime; the second port number is an unreachable port number;

[0130] The second receiving unit 1002 is also used to respectively receive the IP address and the first port number of the public network NAT device, and the new detection message for the IP address and the second port number of the public network NAT device, which are sent by the public network server through the routing device; the new detection message includes the updated current lifetime; the new detection message is sent by the public network server after updating the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same; the updated current lifetime is used to instruct the public network server to determine the number of intranet NAT layers based on the updated current lifetime when it is determined that the responses corresponding to each of the new detection messages are different.

[0131] Based on any of the above embodiments, the above-mentioned intranet NAT layer number determination device 1000 further includes:

[0132] a third sending unit, configured to, when the public network NAT device is a non-secure NAT device, send a port number unreachable response message for the second port number to the public network server through the routing device, and send a third request message for the first port number to the intranet NAT device, when it is determined that the current lifetime minus one is not equal to zero and the destination IP address in the detection message is the IP address of the public network NAT device; the third request message includes a second lifetime; the second lifetime is the current lifetime minus two;

[0133] A third receiving unit is used to receive a timeout response message for the first port number sent by the intranet NAT device when it is determined that the second lifetime minus one is equal to zero;

[0134] The fourth sending unit is used to send a timeout response message for the first port number to the public network server through the routing device.

[0135] Based on any of the above embodiments, the above-mentioned intranet NAT layer number determination device 1000 further includes:

[0136] The fifth sending unit is used to send a timeout response message for the first port number and a timeout response message for the second port number to the public network server through the routing device when it is determined that the current survival time minus one is equal to zero.

[0137] Fig.11 is a schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention, such as Fig.11As shown, the electronic device may include: a processor (processor) 1110, a communication interface (CommunicationsInterface) 1120, a memory (memory) 1130 and a communication bus 1140, wherein the processor 1110, the communication interface 1120, and the memory 1130 communicate with each other through the communication bus 1140. The processor 1110 can call the logic instructions in the memory 1130 to execute the method for determining the number of intranet NAT layers, which method includes: receiving a request message sent by a public network NAT device; the request message includes the IP address and the first port number of the public network NAT device; the request message is a message sent by the intranet device through the intranet NAT device; sending detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through a routing device; the detection message includes the current lifetime; the second port number is an unreachable port number of the public network NAT device; when it is determined that the responses corresponding to each of the detection messages are the same, updating the current lifetime, and sending new detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through the routing device, until it is determined that the responses corresponding to each of the new detection messages are different, determining the number of intranet NAT layers based on the updated current lifetime; the new detection message includes the updated current lifetime.

[0138] Alternatively, the processor 1110 may call the logic instructions in the memory 1130 to execute the method for determining the number of intranet NAT layers, the method comprising:

[0139] A request message is sent to a public network server; the request message includes the IP address and the first port number of the public network NAT device; a detection message for the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through a routing device, is received respectively; the detection message includes the current lifetime; the second port number is an unreachable port number; a new detection message for the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through a routing device, is received respectively; the new detection message includes the updated current lifetime; the new detection message is sent by the public network server after updating the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same; the updated current lifetime is used to instruct the public network server to determine the number of intranet NAT layers based on the updated current lifetime when it is determined that the responses corresponding to each of the new detection messages are different.

[0140] In addition, the logic instructions in the above-mentioned memory 1130 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0141] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the method for determining the number of intranet NAT layers provided by the above methods, and the method includes: receiving a request message sent by a public network NAT device; the request message includes the IP address and the first port number of the public network NAT device; the request message is a message sent by the intranet device through the intranet NAT device; and sending a request message for the IP address and the first port number, and for the public network NAT device to the public network NAT device through a routing device. The detection message includes the current lifetime; the second port number is the unreachable port number of the public network NAT device; when it is determined that the responses corresponding to each of the detection messages are the same, the current lifetime is updated, and new detection messages for the IP address and the first port number, and for the IP address and the second port number are respectively sent to the public network NAT device through the routing device, until it is determined that the responses corresponding to each of the new detection messages are different, and the number of intranet NAT layers is determined based on the updated current lifetime; the new detection message includes the updated current lifetime.

[0142] Alternatively, when the program instructions are executed by a computer, the computer can implement the following method:

[0143] A request message is sent to a public network server; the request message includes the IP address and the first port number of the public network NAT device; a detection message for the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through a routing device, is received respectively; the detection message includes the current lifetime; the second port number is an unreachable port number; a new detection message for the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through a routing device, is received respectively; the new detection message includes the updated current lifetime; the new detection message is sent by the public network server after updating the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same; the updated current lifetime is used to instruct the public network server to determine the number of intranet NAT layers based on the updated current lifetime when it is determined that the responses corresponding to each of the new detection messages are different.

[0144] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the method for determining the number of intranet NAT layers provided by the above-mentioned methods, the method comprising: receiving a request message sent by a public network NAT device; the request message includes the IP address and the first port number of the public network NAT device; the request message is a message sent by the intranet device through the intranet NAT device; sending detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through a routing device; the detection message includes the current lifetime; the second port number is an unreachable port number of the public network NAT device; when it is determined that the responses corresponding to each of the detection messages are the same, updating the current lifetime, and sending new detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through the routing device, until it is determined that the responses corresponding to each of the new detection messages are different, determining the number of intranet NAT layers based on the updated current lifetime; the new detection message includes the updated current lifetime.

[0145] Alternatively, when the computer program is executed by a processor, the following method is implemented:

[0146] A request message is sent to a public network server; the request message includes the IP address and the first port number of the public network NAT device; a detection message for the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through a routing device, is received respectively; the detection message includes the current lifetime; the second port number is an unreachable port number; a new detection message for the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through a routing device, is received respectively; the new detection message includes the updated current lifetime; the new detection message is sent by the public network server after updating the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same; the updated current lifetime is used to instruct the public network server to determine the number of intranet NAT layers based on the updated current lifetime when it is determined that the responses corresponding to each of the new detection messages are different.

[0147] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0148] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0149] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for determining the number of NAT layers in an intranet, characterized in that: Applied to a public network server, the method includes: Receive a request message sent by a public network NAT device; the request message includes the IP address and the first port number of the public network NAT device; the request message is a message sent by an intranet device through the intranet NAT device; Sending detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through a routing device; the detection message includes a current lifetime; the second port number is an unreachable port number of the public network NAT device; When it is determined that the responses corresponding to each of the detection messages are the same, the current lifetime is updated, and new detection messages for the IP address and the first port number, and for the IP address and the second port number are respectively sent to the public network NAT device through the routing device, until it is determined that the responses corresponding to each of the new detection messages are different, and the number of intranet NAT layers is determined based on the updated current lifetime; the new detection message includes the updated current lifetime.

2. The method for determining the number of NAT layers in an intranet according to claim 1, characterized in that: The request message also includes a target lifetime; the target lifetime is related to a preset lifetime and the number of devices; The number of devices is the total number of all devices between the intranet device and the public network server; The determining the number of NAT layers based on the updated current lifetime includes: The difference between the preset survival time and the target survival time is determined as a first survival time; the first survival time is used to represent the total number of all devices between the intranet device and the public network server; The difference between the first lifetime and the updated current lifetime is subtracted by 1 to determine the number of NAT layers in the intranet.

3. The method for determining the number of NAT layers in an intranet according to claim 1 or 2, characterized in that: The determining that the responses corresponding to the detection messages are the same includes: Upon receiving a timeout response message corresponding to each of the detection messages, determining that the responses corresponding to each of the detection messages are the same; or; When no response message corresponding to each of the detection messages is received within a preset timeout period, it is determined that the responses corresponding to each of the detection messages are the same.

4. The method for determining the number of NAT layers in an intranet according to claim 1 or 2, characterized in that: Determining that the responses corresponding to the respective detection messages are different includes: In the case where a timeout response message of the detection message corresponding to the first port number is received and a port unreachable response message of the detection message corresponding to the second port number is received, determining that the responses corresponding to the detection messages are different; or, When a timeout response message of the probe message corresponding to the first port number is received and a response message of the probe message corresponding to the second port number is not received, it is determined that the responses corresponding to the probe messages are different.

5. A method for determining the number of NAT layers in an intranet, characterized in that: Applied to a public network NAT device, the method includes: Sending a request message to a public network server; the request message includes the IP address and the first port number of the public network NAT device; Respectively receiving the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through the routing device; the detection message includes the current lifetime; the second port number is an unreachable port number; Respectively receive new detection messages for the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, which are sent by the public network server through the routing device; the new detection message includes the updated current lifetime; the new detection message is sent by the public network server after updating the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same; the updated current lifetime is used to instruct the public network server to determine the number of intranet NAT layers based on the updated current lifetime when it is determined that the responses corresponding to each of the new detection messages are different.

6. The method for determining the number of NAT layers in an intranet according to claim 5, characterized in that: The method further comprises: When the public network NAT device is a non-secure NAT device, when it is determined that the current lifetime minus one is not equal to zero and it is determined that the destination IP address in the detection message is the IP address of the public network NAT device, a port number unreachable response message for the second port number is sent to the public network server through the routing device, and a third request message for the first port number is sent to the intranet NAT device; the third request message includes a second lifetime; the second lifetime is the current lifetime minus two; receiving a timeout response message for the first port number sent by the intranet NAT device when it is determined that the second lifetime minus one is equal to zero; A timeout response message for the first port number is sent to the public network server through the routing device.

7. The method for determining the number of NAT layers in an intranet according to claim 5, characterized in that: The method further comprises: When the public network NAT device is a non-secure NAT device, when it is determined that the current lifetime minus one is equal to zero, a timeout response message for the first port number and a timeout response message for the second port number are sent to the public network server through the routing device respectively.

8. A device for determining the number of NAT layers in an intranet, characterized in that: include: A first receiving unit, used to receive a request message sent by a public network NAT device; The request message includes the IP address and the first port number of the public network NAT device; The request message is a message sent by the intranet device through the intranet NAT device; A first sending unit is used to send a detection message for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through a routing device; the detection message includes a current lifetime; the second port number is an unreachable port number of the public network NAT device; A determination unit is used to update the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same, and send new detection messages for the IP address and the first port number, and for the IP address and the second port number to the public network NAT device through the routing device, until it is determined that the responses corresponding to each of the new detection messages are different, and the number of intranet NAT layers is determined based on the updated current lifetime; the new detection message includes the updated current lifetime.

9. A device for determining the number of NAT layers in an intranet, characterized in that: include: A second sending unit, used to send a request message to a public network server; The request message includes the IP address and the first port number of the public network NAT device; A second receiving unit is used to receive the IP address and the first port number of the public network NAT device, and the IP address and the second port number of the public network NAT device, respectively, which are sent by the public network server through the routing device; the detection message includes the current survival time; the second port number is an unreachable port number; The second receiving unit is also used to respectively receive the IP address and the first port number of the public network NAT device, and the new detection message for the IP address and the second port number of the public network NAT device, which are sent by the public network server through the routing device; the new detection message includes the updated current lifetime; the new detection message is sent by the public network server after updating the current lifetime when it is determined that the responses corresponding to each of the detection messages are the same; the updated current lifetime is used to instruct the public network server to determine the number of intranet NAT layers based on the updated current lifetime when it is determined that the responses corresponding to each of the new detection messages are different.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, it implements the method for determining the number of intranet NAT layers as described in any one of claims 1 to 4, or implements the method for determining the number of intranet NAT layers as described in any one of claims 5 to 7.