Method and device for detecting network address translation type
By dynamically calculating the timeout and utilizing timestamps and step information in the network address translation type detection of the STUN protocol, the problem of inaccurate detection caused by the unreliability of UDP is solved, and faster and more accurate NAT type identification is achieved.
Patent Information
- Application Number
- CN202511383098.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-25
- Publication Date
- 2025-12-19
AI Technical Summary
Existing network address translation type detection methods based on the STUN protocol cannot accurately determine whether packet loss is UDP or NAT due to the unreliability of the UDP protocol and the lack of reliability guarantees of the STUN protocol. Furthermore, the fixed timeout setting affects the detection speed and accuracy.
By dynamically calculating the timeout during the probing process, the consistency of the response packet is judged by using the timestamp and step information in the probe packet, the communication time is recorded and the timeout is adjusted, and the timeout setting of the probe step is optimized by combining linked lists and weight algorithms.
It achieves accurate detection of network address translation types while improving detection speed and accuracy, and avoids the impact of the unreliability of the UDP protocol on the detection results.
Smart Images

Figure CN121173709A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of communication technology, in particular to a network address translation type detection method and device. BACKGROUND
[0002] At present, the network address translation (NAT) detection based on the STUN protocol generally uses the UDP protocol. The user datagram protocol (UDP) is an unreliable protocol, and the STUN protocol itself does not provide a guarantee for reliability. In addition, it is expected that the STUN protocol cannot receive a response packet of the STUN service at a specific step for some NAT types. Therefore, when a response packet of the STUN service is not received at a certain step, it is not possible to confirm whether the UDP protocol is packet loss or the NAT causes the packet loss.
[0003] Therefore, in the prior art, it is only possible to exclude the possibility of UDP packet loss by setting a timeout time and multiple retries. If a fixed timeout time is used to adapt to all network environments, it is obviously not desirable. If the timeout time is set too large, the time consumption of the detection process will be greatly increased. If the timeout time is set too small, some response packets that can actually be received may be ignored, resulting in inaccurate detection results. In addition, due to the natural unordered and unreliable nature of the UDP protocol, the response packets of the detection may be out of order, which interferes with the calculation of the timeout time. SUMMARY
[0004] Therefore, the present application provides a network address translation type detection method and device, which dynamically calculates the reasonable timeout time of the subsequent step through the pre-step communication time consumption, dynamically adjusts the timeout time, and accurately detects the network address translation type while improving the detection speed.
[0005] The first aspect of the present application provides a network address translation type detection method, comprising:
[0006] sending a detection packet to a STUN service; wherein the message header of the detection packet comprises first detection step information and a first timestamp;
[0007] if a response packet fed back by the STUN service is received within a first timeout time, determining whether the first detection step information and second detection step information are consistent; wherein the message header of the response packet comprises the second detection step information and a second timestamp;
[0008] if it is determined that the first detection step information and the second detection step information are consistent, determining the communication time consumption according to the current timestamp and the second timestamp;
[0009] record the communication time consumption into a linked list, determine a second timeout time according to all the communication time consumption in the linked list, and configure the second timeout time as the first timeout time of the next probing step of the current probing step;
[0010] determine a network address translation type or next probing step information according to the probing step information, the feedback information, the public network information and the intranet information; wherein the feedback information is whether a response packet of STUN service feedback is received within a retry number threshold.
[0011] Optionally, the network address translation type probing method further comprises:
[0012] If the response packet of STUN service feedback is not received within the timeout time, the probing packet is re-sent to the STUN service until the retry number threshold is reached or the response packet of STUN service feedback is received.
[0013] Optionally, the second timeout time is determined according to all the communication time consumption, comprising:
[0014] determining the total number of the communication time consumption in the linked list;
[0015] allocating a weight to each communication time consumption based on the total number of the communication time consumption;
[0016] determining the second timeout time according to all the communication time consumption and the weight corresponding to the communication time consumption.
[0017] Optionally, the network address translation type probing method further comprises:
[0018] If it is judged that the first probing step information and the second probing step information are inconsistent, the response packet of STUN service feedback is discarded.
[0019] Optionally, the probing step information is divided into only sending a probing packet, sending a probing packet and carrying a changed ip address attribute, and sending a probing packet and carrying a changed port attribute.
[0020] Optionally, the network address translation type is divided into disabling UDP protocol, restricted cone network address translation type, port restricted cone network address translation type, symmetric network address translation type, full cone network address translation type, no network address translation type and no firewall, and no network address translation type but with firewall.
[0021] The second aspect of the present application provides a network address translation type probing device, comprising:
[0022] a sending unit configured to send a probing packet to a STUN service; wherein the message header of the probing packet comprises first probing step information and a first timestamp;
[0023] a judging unit, configured to judge whether the first probe step information and the second probe step information are consistent if a response packet fed back by the STUN service is received within the first timeout time, wherein the message header of the response packet comprises the second probe step information and a second timestamp;
[0024] a communication time consumption determining unit, configured to determine the communication time consumption according to the current timestamp and the second timestamp if the judging unit judges that the first probe step information and the second probe step information are consistent;
[0025] a configuring unit, configured to record the communication time consumption into a linked list, determine a second timeout time according to all the communication time consumptions in the linked list, and configure the second timeout time as the first timeout time of the next probe step of the current probe step;
[0026] a type determining unit, configured to determine a network address translation type or next probe step information according to the probe step information, feedback information, public network information and internal network information, wherein the feedback information is whether a response packet fed back by the STUN service is received within a retry number threshold.
[0027] Optionally, the network address translation type probe device further comprises:
[0028] a retry unit, configured to resend a probe packet to the STUN service until a retry number threshold is reached or the response packet fed back by the STUN service is received if the response packet fed back by the STUN service is not received within the timeout time.
[0029] Optionally, the configuring unit comprises:
[0030] a total number determining unit, configured to determine a total number of the communication time consumptions in the linked list;
[0031] a weight allocating unit, configured to allocate a weight to each communication time consumption based on the total number of the communication time consumptions;
[0032] a second timeout time determining unit, configured to determine the second timeout time according to all the communication time consumptions and the weights corresponding to the communication time consumptions.
[0033] Optionally, the network address translation type probe device further comprises:
[0034] a discarding unit, configured to discard the response packet fed back by the STUN service if the judging unit judges that the first probe step information and the second probe step information are inconsistent.
[0035] Optionally, the detection step information is classified into sending only the detection packet, sending the detection packet and carrying the changed IP address attribute, and sending the detection packet and carrying the changed port attribute.
[0036] Optionally, the network address translation type is classified into disabling the UDP protocol, the restricted cone network address translation type, the port restricted cone network address translation type, the symmetric network address translation type, the full cone network address translation type, no network address translation type and no firewall, and no network address translation type but with firewall.
[0037] The third aspect of the present application provides an electronic device, comprising:
[0038] one or more processors;
[0039] a storage device having one or more programs stored thereon;
[0040] When the one or more programs are executed by the one or more processors, the one or more processors implement the network address translation type detection method according to any one of the first aspect.
[0041] The fourth aspect of the present application provides a computer storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the network address translation type detection method according to any one of the first aspect.
[0042] According to the above scheme, the present application provides a network address translation type detection method and device, a detection packet carrying first detection step information and a first timestamp is sent to a STUN service; if the first detection step information is consistent with second detection step information in a response packet fed back by the STUN service within a first timeout time, the communication time consumption is determined according to a current timestamp and the second timestamp; the communication time consumption is recorded in a linked list, and a second timeout time is determined according to all the communication time consumption in the linked list, and the second timeout time is configured as the first timeout time of the next detection step of the current detection step; and the network address translation type or the next detection step information is determined according to the detection step information, the feedback information, the public network information and the intranet information; the reasonable timeout time of the post-step is dynamically calculated through the pre-step communication time consumption, and the network address translation type is accurately detected while the detection speed is improved. BRIEF DESCRIPTION OF DRAWINGS
[0043] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiment or prior art description. Obviously, the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of the provided drawings.
[0044] Figure 1 A flow chart of a network address translation type detection method based on a STUN protocol;
[0045] Figure 2 A specific flow chart of a network address translation type detection method provided by an embodiment of the present application;
[0046] Figure 3 A schematic diagram of a standard STUN message header format defined by RFC5389;
[0047] Figure 4 A schematic diagram of a STUN message header format provided by another embodiment of the present application;
[0048] Figure 5 A flow chart of a method for determining a second timeout provided by another embodiment of the present application;
[0049] Figure 6 A flow chart of a method for updating a timeout provided by another embodiment of the present application;
[0050] Figure 7 A schematic diagram of a network address translation type detection device provided by another embodiment of the present application;
[0051] Figure 8 A schematic diagram of an electronic device for implementing a network address translation type detection method provided by another embodiment of the present application. DETAILED DESCRIPTION
[0052] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present application.
[0053] The term “comprising” and variations thereof as used in the present document are open-ended, that is, “including but not limited to”. The term “based on” is “based at least in part on”. The term “one embodiment” means “at least one embodiment”; the term “another embodiment” means “at least one additional embodiment”; the term “some embodiments” means “at least some embodiments”. Related definitions of other terms will be given in the following description.
[0054] It should be noted that the information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of the relevant data need to comply with the relevant laws, regulations and standards of the country and region.
[0055] It should be noted that the concepts of "first", "second" and the like mentioned in the present application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0056] It should be noted that the modification of "one", "multiple" mentioned in the present application is illustrative but not limiting, and those skilled in the art should understand that unless otherwise explicitly indicated in the context, it should be understood as "one or more".
[0057] As shown in Figure 1 is a flowchart for NAT type detection based on the STUN protocol (Session Traversal Utilities for NAT) defined by RFC5389.
[0058] Wherein, STUN-MSG is a detection information (detection packet), the Mapped-Address (mapped address) attribute appears in the Binding Response (response packet) message of STUN, and the source IP address and port (port) seen by the STUN server when receiving the client request can be obtained by analyzing it, localip is the intranet ip, outerip is the public network ip, outerport is the public network port, change-ip attribute is the change ip address attribute, and change-port attribute is the change port address attribute.
[0059] Since the STUN protocol requires the node to communicate with the STUN service through multiple rounds of UDP probe packets, but the STUN protocol is expected to not receive a response packet from the STUN service at a certain step for some NAT types (such as all non-cone-shaped NATs), it is not possible to determine whether the UDP protocol packet is lost or the NAT causes the packet to be lost when a response packet from the STUN service is not received at a certain step. The possibility of UDP packet loss can only be ruled out by setting a timeout and retrying multiple times. It is obviously not desirable to use a fixed timeout to adapt to all network environments, because if the timeout is set too large, it will greatly increase the time consumption of the detection process; if the timeout is set too small, it may incorrectly ignore some response packets that can be reached, resulting in inaccurate detection results. In addition, due to the natural unordered and unreliable nature of the UDP protocol, the response packets of the detection may be out of order, interfering with the calculation of the timeout.
[0060] To this end, an embodiment of the present application provides a network address translation type detection method, as shown in the following Figure 2 specifically comprising the following steps:
[0061] S201, sending a detection packet to a STUN service.
[0062] The message header of the detection packet includes first detection step information and a first timestamp.
[0063] In the actual application process of the present application, the first detection step information can be but is not limited to a simple identifier, for example: 1.1, S1.1, Sa, etc., which is not limited here.
[0064] As shown in the following Figure 3 is the standard STUN message header format in the prior art, which is fixed at 20 bytes, a total of 160 bits, wherein: 0-1, a total of 2 bits, fixedly filled with 0; 2-15, a total of 14 bits, indicating the type of the STUN message; 16-31, a total of 16 bits, indicating the length of the STUN message (excluding the message header); 32-63, a total of 32 bits, magic number, fixedly filled with 0x2112A442; 64-159, a total of 96 bits, unique transaction ID, generated by the Client, identifying the same transaction request and response.
[0065] As shown in the following Figure 4As shown in the STUN message header format in the application, the message header is fixed as 20 bytes, totally 160 bits, wherein: 0-1 bits, totally 2 bits, fixedly filled with 0; 2-15 bits, totally 14 bits, indicating the type of the STUN message; 16-31 bits, totally 16 bits, indicating the length of the STUN message (excluding the message header); 32-63 bits, totally 32 bits, magic number, fixedly filled with 0x2112A442; 64-95 bits, i.e. 0-31 bits of the transaction ID, totally 32 bits, filled with a current time stamp at the millisecond level; 96-103 bits, i.e. 32-39 bits of the transaction ID, totally 8 bits, filled with the step number to which the current message belongs in the probe process; and 104-159 bits, i.e. 40-95 bits of the transaction ID, totally 56 bits, filled with a random number.
[0066] S202, if the response packet of the STUN service feedback is received within the first timeout time, judging whether the first probe step information and the second probe step information are consistent.
[0067] The message header of the response packet comprises the second probe step information and the second time stamp.
[0068] In the practical application of the application, if the response packet of the STUN service feedback is not received within the timeout time, the probe packet is re-sent to the STUN service until the retry number threshold is reached, or the response packet of the STUN service feedback is received.
[0069] The retry number threshold is set or changed by experts or relevant authorized staff in advance, which is not limited here.
[0070] Specifically, if it is judged that the first probe step information and the second probe step information are consistent, step S203 is executed; if it is judged that the first probe step information and the second probe step information are inconsistent, the response packet of the STUN service feedback is discarded.
[0071] In the prior art, due to the natural unordered and unreliable characteristics of the UDP protocol, the response packet of the probe may be out of order to interfere with the calculation of the timeout time, for example: Figure 1 As shown, at step 2.1, the response packet is not received due to network jitter (the packet may be on the way), including retry, at this time, step 2.2 is continued to be executed, if the response packet of step 2.1 comes first than the response packet of step 2.2, the result of step 2.2 will be affected. Therefore, the application directly discards the processing when the step information in the response packet header is inconsistent with the current step information (the first probe step), only the response packet of the current step is processed. Thus, the problem caused by packet out of order is solved.
[0072] S203, determining the communication time consumption according to the current time stamp and the second time stamp.
[0073] In the practical application of the present application, the communication time consumption T can be calculated by the following calculation method n :
[0074] T n =T-T b ; wherein T is the current timestamp, T b is the second timestamp.
[0075] S204, record the communication time consumption in the linked list, and determine the second timeout time according to all the communication time consumption in the linked list.
[0076] Optionally, in another embodiment of the present application, an embodiment of step S204 includes, as shown in Figure 5 :
[0077] S501, determine the total number of communication time consumption in the linked list.
[0078] S502, assign a weight to each communication time consumption based on the total number of communication time consumption.
[0079] In the specific implementation process of the present application, the weight assignment can be linearly decreasing from the latest communication time consumption data to the earliest communication time consumption data, but is not limited thereto.
[0080] S503, determine the second timeout time according to all the communication time consumption and the weight corresponding to the communication time consumption.
[0081] In the practical application of the present application, the weighted sum of the communication time consumption and the weight corresponding to the communication time consumption can be calculated first, and then the total weight is calculated, and finally the quotient of the weighted sum and the total weight is taken as the second timeout time.
[0082] Specifically, the second timeout time can be calculated by the following calculation formula;
[0083] ;
[0084] wherein T is the second timeout time, n is the total number of communication time consumption in the linked list, T i is the time consumption of the i-th record (T n represents the latest one, T n-1 represents the second new one, and so on until T1 represents the earliest one in the linked list).
[0085] S205, configure the second timeout time as the first timeout time of the next detection step of the current detection step.
[0086] The second timeout time is dynamically calculated by a pre-step communication time consumption, and is configured as the first timeout time of the next probe step, so that the timeout time of the post-step is more reasonable, and the speed of the probe is improved while the network address translation type is accurately probed.
[0087] As shown in Figure 6 Fig. 1 is a flowchart of updating a timeout time provided by an embodiment of the present application. First, an initial timeout time Tx is set, which is also the timeout time of the first step. In the process of NAT type probing, before a probe packet is sent to a STUN service, a STUN Message Builder adds current step information (first probe step information) and a current timestamp (first timestamp) in a transaction ID field of a message header of an existing probe in the STUN Message Builder, and waits for a response packet within the Tx time. If no response packet is received within the Tx time, a retry is performed until a retry number threshold is reached, or a response packet fed back by the STUN service is received. If a response packet is received within the Tx time, a STUN Message Parser parses the response packet (STUN response message) to obtain second probe step information and a second timestamp. If the first probe step information and the second probe step information are inconsistent, the response packet fed back by the STUN service is discarded. If the first probe step information and the second probe step information are consistent, a Clac Latest Tv (timeout time updating unit) calculates a communication time consumption Tn of this time according to the current timestamp and the second timestamp, stores the Tn in a time consumption record linked list, performs a weighted moving average evaluation on all communication time consumptions in the time consumption record linked list to obtain a latest timeout time Tv (second timeout time), configures the second timeout time as the first timeout time of the next probe step of the current probe step (Tx=Tv), and performs a probe of the next step or ends the probe.
[0088] S206, determining a network address translation type or next probe step information according to the probe step information, feedback information, public network information and internal network information.
[0089] The feedback information is whether a response packet fed back by the STUN service is received within a retry number threshold.
[0090] In the specific implementation process of the present application, the probe step information is divided into only sending a probe packet (such as steps 1.1 and 2.2 in Figure 1 ), sending a probe packet and carrying a changed ip address attribute (such as steps 2.1 and 1.2 in Figure 1 ), and sending a probe packet and carrying a changed port attribute (such as step 3 in Figure 1 ).
[0091] In the implementation of the present application, the network address translation types are classified into UDP Block, Restricted Cone NAT / NAT2, Port-Restricted Cone NAT / NAT3, Symmetric NAT / NAT4, Full Cone NAT / NAT1, no NAT and no firewall, and no NAT but with firewall.
[0092] From the above solution, the present application provides a network address translation type detection method, which sends a detection packet carrying first detection step information and a first timestamp to a STUN service; if a response packet fed back by the STUN service is received within a first timeout time, if the first detection step information is consistent with second detection step information in the response packet, then the communication time consumption is determined according to a current timestamp and the second timestamp; the communication time consumption is recorded in a linked list, and a second timeout time is determined according to all the communication time consumptions in the linked list, and the second timeout time is configured as the first timeout time of the next detection step of the current detection step; and the network address translation type or the next detection step information is determined according to the detection step information, the feedback information, public network information and internal network information; the present application dynamically calculates the reasonable timeout time of the post-step through the pre-step communication time consumption, and improves the detection speed while accurately detecting the network address translation type.
[0093] Another embodiment of the present application provides a network address translation type detection device, as shown in the accompanying drawings, which specifically comprises: Figure 7
[0094] The sending unit 701 is configured to send a detection packet to a STUN service.
[0095] The message header of the detection packet comprises first detection step information and a first timestamp.
[0096] The judging unit 702 is configured to judge whether the first detection step information is consistent with second detection step information if a response packet fed back by the STUN service is received within a first timeout time.
[0097] The message header of the response packet comprises second detection step information and a second timestamp.
[0098] The communication time consumption determining unit 703 is configured to determine the communication time consumption according to a current timestamp and the second timestamp if the judging unit 702 judges that the first detection step information is consistent with the second detection step information.
[0099] The configuration unit 704 is configured to record the communication time consumption into a linked list, determine a second timeout time according to all the communication time consumption in the linked list, and configure the second timeout time as the first timeout time of the next probing step of the current probing step.
[0100] The type determination unit 705 is configured to determine a network address translation type or the next probing step information according to the probing step information, the feedback information, the public network information and the intranet information.
[0101] The feedback information is whether a response packet of the STUN service feedback is received within a retry number threshold.
[0102] The specific working process of the units disclosed in the above embodiments of the application can be referred to the corresponding method embodiment contents, for example, as shown in the above method embodiment, and details are not described herein. Figure 2
[0103] Optionally, the probing step information is divided into only sending a probing packet, sending a probing packet and carrying a changed IP address attribute, and sending a probing packet and carrying a changed port attribute.
[0104] Optionally, the network address translation type is divided into disabling the UDP protocol, a limited cone network address translation type, a port limited cone network address translation type, a symmetric network address translation type, a full cone network address translation type, no network address translation type and no firewall, and no network address translation type but with a firewall.
[0105] The specific working process of the units disclosed in the above embodiments of the application can be referred to the corresponding method embodiment contents, and details are not described herein.
[0106] Optionally, in another embodiment of the application, an embodiment of the probing device of the network address translation type further comprises:
[0107] The retry unit is configured to resend the probing packet to the STUN service until the retry number threshold is reached or the response packet of the STUN service feedback is received, if the response packet of the STUN service feedback is not received within the timeout time.
[0108] The specific working process of the units disclosed in the above embodiments of the application can be referred to the corresponding method embodiment contents, and details are not described herein.
[0109] Optionally, in another embodiment of the application, an embodiment of the configuration unit further comprises:
[0110] The total number determination unit is configured to determine the total number of the communication time consumption in the linked list.
[0111] The weight allocation unit is configured to allocate a weight to each communication time consumption based on the total number of the communication time consumption.
[0112] The second timeout time determining unit is configured to determine the second timeout time according to all the communication time consumptions and the weights corresponding to the communication time consumptions.
[0113] The specific working process of the units disclosed in the above embodiments of the present application can be referred to the corresponding method embodiment contents, for example, as shown in the above method embodiment, and will not be repeated here. Figure 5
[0114] Optionally, in another embodiment of the present application, an implementation of the network address translation type detection device further comprises:
[0115] The discarding unit is configured to discard the response packet fed back by the STUN service if the judging unit judges that the first detection step information and the second detection step information are inconsistent.
[0116] The specific working process of the units disclosed in the above embodiments of the present application can be referred to the corresponding method embodiment contents, for example, as shown in the above method embodiment, and will not be repeated here.
[0117] As can be seen from the above scheme, the present application provides a network address translation type detection device, which sends a detection packet carrying first detection step information and a first timestamp to a STUN service; if the response packet fed back by the STUN service is received within a first timeout time, if the first detection step information is consistent with the second detection step information in the response packet, the communication time consumption is determined according to a current timestamp and a second timestamp; the communication time consumption is recorded in a linked list, and the second timeout time is determined according to all the communication time consumptions in the linked list, and the second timeout time is configured as the first timeout time of the next detection step of the current detection step; and the network address translation type or the next detection step information is determined according to the detection step information, the feedback information, the public network information and the internal network information; the present application dynamically calculates the reasonable timeout time of the post-step through the communication time consumption of the pre-step, and improves the detection speed while accurately detecting the network address translation type.
[0118] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, and without limitation, illustrative types of hardware logic components that can be used include Field-programmable Gate Arrays (FPGAs), Application-specific Integrated Circuits (ASICs), Application-specific Standard Products (ASSPs), System-on-a-chip systems (SOCs), Complex Programmable Logic Devices (CPLDs), etc.
[0119] Another embodiment of the present application provides an electronic device, as shown in Figure 8 The electronic device comprises:
[0120] one or more processors 801.
[0121] a storage device 802 having one or more programs stored thereon.
[0122] The one or more programs, when executed by the one or more processors 801, enable the one or more processors 801 to implement the network address translation type probing method as described in the above embodiments.
[0123] Another embodiment of the present application provides a computer storage medium having stored thereon a computer program, wherein the computer program, when executed by a processor, implements the network address translation type probing method as described in the above embodiments.
[0124] In the context of the present application, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium will include one or more of the following: an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0125] It should be noted that the computer readable medium in the present application can be a computer readable signal medium or a computer readable storage medium or any combination of the two. The computer readable storage medium may, for example, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or apparatus, or any combination of the above. More specific examples of the computer readable storage medium can include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, the computer readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device or apparatus. In the present application, the computer readable signal medium can include a data signal carried in a baseband or as a part of a carrier wave, which carries computer readable program code. Such a propagated data signal can take various forms, including but not limited to an electromagnetic signal, an optical signal or any suitable combination of the above. The computer readable signal medium can also be any computer readable medium other than the computer readable storage medium, which can send, propagate or transmit a program for use by or in conjunction with an instruction execution system, device or apparatus. The program code contained in the computer readable medium can be transmitted by any suitable medium, including but not limited to a wire, a cable, an RF (radio frequency) or the like, or any suitable combination of the above.
[0126] The computer readable medium described above can be contained in the electronic device described above; or can exist separately and not be assembled into the electronic device.
[0127] Another embodiment of the present application provides a computer program product, which, when executed, performs the network address translation type probing method described above.
[0128] In particular, according to embodiments of the present application, the processes described above with reference to the flowcharts can be implemented as a computer software program. For example, embodiments of the present application include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program comprising program code for performing the methods illustrated by the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network by a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processing device, the above-mentioned functions defined in the methods of the embodiments of the present application are performed.
[0129] Although the subject matter has been described in language specific to structural features and / or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.
[0130] Although specific implementation details have been included in the above discussion, these should not be construed as limiting the scope of the application. Some of the features described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment can also be implemented separately or in any appropriate subcombination. For the sake of clarity, the description has not attempted to include all combinations of these various features with each other.
[0131] The above description is merely exemplary of the application and the application principles that have been employed. It is to be understood that the application is not limited to the specific devices, methods, or the like, described above, and that numerous modifications can be made by one skilled in the art without departing from the application. For example, one of ordinary skill in the art will recognize that the application is not limited to the specific implementations described above, but will also extend to other implementations that are consistent with the principles of the application.
Claims
1. A method of probing of the network address translation type, characterized in that, The method comprises the following steps: sending a probe packet to a STUN service; wherein the message header of the probe packet comprises first probe step information and a first timestamp; if a response packet fed back by the STUN service is received within a first timeout time, judging whether the first probe step information is consistent with second probe step information; wherein the message header of the response packet comprises the second probe step information and a second timestamp; if it is judged that the first probe step information is consistent with the second probe step information, determining a communication time consumption according to a current timestamp and the second timestamp; recording the communication time consumption into a linked list, and determining a second timeout time according to all the communication time consumptions in the linked list, and configuring the second timeout time as the first timeout time of a next probe step of a current probe step; determining a network address translation type or next probe step information according to the probe step information, feedback information, public network information and internal network information; wherein the feedback information is whether a response packet fed back by the STUN service is received within a retry number threshold.
2. The network address translation type probing method of claim 1, wherein, The method further comprises the following steps: if the response packet fed back by the STUN service is not received within the timeout time, resending the probe packet to the STUN service until the retry number threshold is reached or the response packet fed back by the STUN service is received.
3. The network address translation type probing method of claim 1, wherein, The step of determining the second timeout time according to all the communication time consumptions in the linked list comprises the following steps: determining the total number of the communication time consumptions in the linked list; allocating a weight to each communication time consumption based on the total number of the communication time consumptions; determining the second timeout time according to all the communication time consumptions and the weights corresponding to the communication time consumptions.
4. The network address translation type probing method of claim 1, wherein, The method further comprises the following step: if it is judged that the first probe step information is not consistent with the second probe step information, discarding the response packet fed back by the STUN service.
5. The network address translation type probing method of claim 1, wherein, The probe step information is divided into only sending a probe packet, sending a probe packet and carrying a changed IP address attribute, and sending a probe packet and carrying a changed port attribute.
6. The network address translation type probing method of claim 1, wherein, The network address translation type is divided into disabling a UDP protocol, a restricted cone network address translation type, a port restricted cone network address translation type, a symmetric network address translation type, a full cone network address translation type, no network address translation type and no firewall, and no network address translation type but with a firewall.
7. A network address translation type probing apparatus characterized by comprising: The method comprises the following steps: a sending unit configured to send a probe packet to a STUN service; wherein the message header of the probe packet comprises first probe step information and a first timestamp; a judging unit configured to, if a response packet fed back by the STUN service is received within a first timeout time, judge whether the first probe step information is consistent with second probe step information; wherein the message header of the response packet comprises the second probe step information and a second timestamp; a communication time consumption determining unit configured to, if the judging unit judges that the first probe step information is consistent with the second probe step information, determine a communication time consumption according to a current timestamp and the second timestamp; a configuring unit configured to record the communication time consumption into a linked list, and determine a second timeout time according to all the communication time consumptions in the linked list, and configure the second timeout time as the first timeout time of a next probe step of a current probe step; and The type determining unit is configured to determine a network address translation type or next probe step information according to the probe step information, the feedback information, the public network information and the intranet information, wherein the feedback information is whether a response packet of STUN service feedback is received within a retry number threshold.
8. The network address translation type probe apparatus according to claim 7, wherein Further comprising: The retry unit is configured to resend the probe packet to the STUN service until a retry number threshold is reached or the response packet of STUN service feedback is received if the response packet of STUN service feedback is not received within a timeout time.
9. The network address translation type probe apparatus according to claim 7, wherein, The configuration unit comprises: The total number determining unit is configured to determine a total number of the communication time consumptions in the linked list; The weight allocating unit is configured to allocate a weight to each communication time consumption based on the total number of the communication time consumptions; The second timeout time determining unit is configured to determine a second timeout time according to all the communication time consumptions and the weights corresponding to the communication time consumptions.
10. The network address translation type probe apparatus according to claim 7, wherein, Further comprising: The discard unit is configured to discard the response packet of STUN service feedback if the first probe step information and the second probe step information are inconsistent as determined by the judging unit.