Network address translation traversal method and device, equipment and storage medium
By analyzing the request packet and response packet of the user equipment, using the port prediction model to perform port prediction, the target public network connection between the user equipment and the network address conversion device is realized, solving the problem of insufficient communication accuracy in the NAT environment and improving communication efficiency and stability.
Patent Information
- Application Number
- CN202510261930.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-06
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2045-03-06
AI Technical Summary
The prior art has problems of insufficient accuracy and limited application when dealing with communication in NAT environment, especially in cross-subnets or NAT-hindered communication scenarios, where communication delay and packet loss rates are high, affecting communication efficiency and stability.
By analyzing the request packet and response packet of the user equipment, determining the information type of its network address translation information, and using the port prediction model to perform port prediction, realizing the target public network connection between the user equipment and the network address translation device. After a successful connection, the broadcast device discovers the request, exchanges the device information, and establishes a communication link for communication.
It realizes rapid conversion of network addresses and automatic device discovery, reduces communication delay and packet loss rate, improves communication efficiency and stability, and is suitable for home networks, enterprise networks and mobile network environments.
Smart Images

Figure CN119766772A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network communications, and in particular to a network address translation traversal method, device, equipment and storage medium. Background Art
[0002] With the rapid development of the Internet of Things, seamless connection and efficient communication between smart devices have become the key to the development of the industry. However, the existence of NAT (Network Address Translation) makes direct communication between devices complicated and unstable, especially in cross-subnet or NAT-blocked communication scenarios, communication between devices often needs to be forwarded through an intermediate server, which not only increases the delay and cost of communication, but also reduces the reliability and security of communication.
[0003] In the prior art, the communication problem in the NAT environment is usually solved by the STUN (Simple Traversal of UDP Through NAT; UDP, namely User Datagram Protocol) protocol and the mDNS (Multicast DNS; DNS, namely Domain Name System) protocol. However, the existing STUN and mDNS protocols still have certain limitations when dealing with complex network environments. The STUN protocol may not be accurate enough when detecting certain types of NAT, resulting in traversal failure, while the mDNS protocol is mainly applicable to local area networks, and is not effective for communication scenarios across subnets or where NAT is obstructed. Summary of the invention
[0004] In view of this, the purpose of the present invention is to provide a network address translation traversal method, device, equipment and storage medium, which can realize the rapid conversion of network addresses and automatic discovery of devices, so as to reduce communication delay and packet loss rate, thereby improving communication efficiency and stability. The specific scheme is as follows:
[0005] In a first aspect, the present application discloses a network address translation traversal method, which is applied to a network address translation device, comprising:
[0006] Parsing a request packet and a response packet of a preset network protocol corresponding to the user equipment, so as to determine the information type of the network address translation information corresponding to the user equipment based on the data information obtained by the parsing;
[0007] Input the information type into a port prediction model in a preset traversal strategy library, so as to perform port prediction based on the information type and the network address translation information through the port prediction model, and obtain a target predicted port combination corresponding to the user device, so that the user device can connect to the target public network corresponding to the network address translation device based on the target predicted port combination;
[0008] If the user equipment successfully connects to the target public network, broadcasting the device discovery request sent by the user equipment, and after determining the to-be-matched device that responds to the device discovery request, exchanging device information of the user equipment and the to-be-matched device;
[0009] A communication link is established between the user equipment and the device to be matched according to the device information, so as to perform communication between the user equipment and the device to be matched based on the communication link.
[0010] Optionally, parsing a request packet and a response packet of a preset network protocol corresponding to the user equipment to determine the information type of the network address translation information corresponding to the user equipment based on the data information obtained by the parsing includes:
[0011] If a request packet of a preset network protocol sent by a user device is received, the request packet is parsed to determine first data information corresponding to the request packet of the preset network protocol;
[0012] Determine the actual value of the data in the target public network corresponding to the local data information, and use the actual value of the data as the second data information corresponding to the response packet of the preset network protocol;
[0013] Comparing the first data information and the second data information, if the comparison result indicates that the port number and source address corresponding to the first data information are consistent with the port number and source address corresponding to the second data information, and the second data information includes response data of different addresses, then determining that the information type of the network address translation information corresponding to the user equipment is full cone;
[0014] If the second data information only includes response data of the same address, it is determined that the information type of the network address translation information corresponding to the user equipment is a restricted cone.
[0015] Optionally, the step of inputting the information type into a port prediction model in a preset traversal strategy library, performing port prediction based on the information type and the network address translation information through the port prediction model, and obtaining a target predicted port combination corresponding to the user device, so that the user device connects to the target public network corresponding to the network address translation device based on the target predicted port combination, further includes:
[0016] Collecting interaction data corresponding to each user device and the preset network protocol; the interaction data includes data in a request packet and a response packet corresponding to each user data and a connection success rate corresponding to each user device;
[0017] Preprocessing the interaction data, and performing feature extraction on the obtained preprocessed interaction data to obtain feature data corresponding to the preprocessed interaction data;
[0018] The pre-trained model is trained by the feature data to obtain a port prediction model, and the port prediction model is integrated into a preset traversal strategy library.
[0019] Optionally, the inputting the information type into a port prediction model in a preset traversal strategy library, so as to perform port prediction based on the information type and the network address translation information through the port prediction model to obtain a target predicted port combination corresponding to the user equipment, includes:
[0020] Initialize a preset traversal policy library, and input the information type into a port prediction model in the preset traversal policy library, so as to match a corresponding target network address translation traversal policy in the preset traversal policy library based on the information type through the port prediction model, so that the user device connects to the target public network corresponding to the network address translation device based on the target network address translation traversal policy;
[0021] If the user device fails to connect to the target public network corresponding to the network address translation device based on the target network address translation traversal strategy, port prediction is performed based on the information type and the network address translation information through the port prediction model to obtain a target predicted port combination corresponding to the user device.
[0022] Optionally, the broadcasting of the device discovery request sent by the user equipment and, after determining a to-be-matched device that responds to the device discovery request, exchanging device information of the user equipment and the to-be-matched device includes:
[0023] Broadcasting the device discovery request sent by the user equipment, and screening and sorting the received response messages to determine a target response message corresponding to the device discovery request among the response messages;
[0024] Determine the to-be-matched device corresponding to the target response message, and respectively obtain first device information corresponding to the user equipment and second device information corresponding to the to-be-matched device;
[0025] Encrypting the first device information and the second device information respectively by a preset encryption algorithm to obtain first encrypted device information corresponding to the first device information and second encrypted device information corresponding to the second device information;
[0026] The first encrypted device information is sent to the device to be matched, and the second encrypted device information is sent to the user device.
[0027] Optionally, establishing a communication link between the user equipment and the to-be-matched device according to the device information includes:
[0028] An Internet communication protocol stack is configured between the user device and the device to be matched, so as to establish a communication link between the user device and the device to be matched based on the network address and port number in the device information through the Internet communication protocol stack.
[0029] Optionally, the network address translation traversal method further includes:
[0030] Real-time monitoring of communication indicators of the user equipment and the to-be-matched equipment communicating through the communication link;
[0031] If the communication indicator indicates that there is data packet loss, a data retransmission request is sent to the data sender through the user equipment and the data receiving direction in the to-be-matched device to re-transmit the data;
[0032] If the communication indicator indicates that the communication flow of the communication link reaches a preset flow threshold, a standby communication link between the user equipment and the device to be matched is enabled for load balancing.
[0033] In a second aspect, the present application discloses a network address translation traversal device, which is applied to a network address translation device, comprising:
[0034] An information type determination module, used to parse a request packet and a response packet of a preset network protocol corresponding to a user device, so as to determine the information type of the network address translation information corresponding to the user device based on the data information obtained by the parsing;
[0035] A local area network connection module, used for inputting the information type into a port prediction model in a preset traversal strategy library, so as to perform port prediction based on the information type and the network address translation information through the port prediction model, and obtain a target predicted port combination corresponding to the user device, so that the user device can connect to the target public network corresponding to the network address translation device based on the target predicted port combination;
[0036] An information exchange module, configured to broadcast a device discovery request sent by the user equipment if the user equipment successfully connects to the target public network, and exchange device information of the user equipment and the device to be matched after determining a device to be matched that responds to the device discovery request;
[0037] A communication link establishing module is used to establish a communication link between the user equipment and the device to be matched according to the device information, so as to perform communication between the user equipment and the device to be matched based on the communication link.
[0038] In a third aspect, the present application discloses an electronic device, comprising:
[0039] Memory, used to store computer programs;
[0040] The processor is used to execute the computer program to implement the network address translation traversal method as described above.
[0041] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the network address translation traversal method as described above.
[0042] In the present application, the request packet and response packet of the preset network protocol corresponding to the user device can be parsed to determine the information type of the network address translation information corresponding to the user device based on the data information obtained by the analysis; the information type is input into the port prediction model in the preset traversal policy library to perform port prediction based on the information type and the network address translation information through the port prediction model to obtain the target predicted port combination corresponding to the user device, so that the user device can connect to the target public network corresponding to the network address translation device based on the target predicted port combination; if the user device successfully connects to the target public network, the device discovery request sent by the user device is broadcast, and after determining the device to be matched that responds to the device discovery request, the device information of the user device and the device to be matched is exchanged; a communication link between the user device and the device to be matched is established based on the device information, so as to communicate between the user device and the device to be matched based on the communication link.
[0043] It can be seen that through the method of the present application, the user device request packet and the corresponding response packet can be parsed to determine the information type of the network address translation information of the user device based on the obtained data information; the port prediction model is used to perform port prediction based on the information type and the network address translation information, so that the user device can connect to the target public network corresponding to the network address translation device based on the predicted target prediction port combination; if the connection is successful, the device discovery request sent by the user device is broadcast, and after the corresponding device to be matched is determined, the device information of the user device and the device to be matched is exchanged to establish a communication link between the user device and the device to be matched according to the device information. In this way, rapid conversion of network addresses and automatic discovery of devices can be achieved to reduce communication delays and packet loss rates, thereby improving communication efficiency and stability, and providing users with a smooth communication experience whether in a home network, enterprise network or mobile network environment. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0045] Figure 1 A flow chart of a network address translation traversal method disclosed in this application;
[0046] Figure 2 A flowchart of a specific network address translation traversal method disclosed in this application;
[0047] Figure 3 A schematic diagram of the architecture of a network address translation traversal method disclosed in this application;
[0048] Figure 4 A schematic diagram of the structure of a network address translation traversal device disclosed in this application;
[0049] Figure 5 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0050] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only 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.
[0051] In the prior art, the STUN protocol and the mDNS protocol are usually used to solve the communication problem in the NAT environment. However, the existing STUN and mDNS protocols still have certain limitations when dealing with complex network environments. The STUN protocol may not be accurate enough when detecting certain types of NAT, resulting in traversal failure, while the mDNS protocol is mainly applicable to local area networks and is not effective for communication scenarios across subnets or where NAT is obstructed.
[0052] In order to overcome the above technical problems, the present application discloses a network address translation traversal method, apparatus, device and storage medium, which can integrate and optimize the STUN protocol and the mDNS protocol, and realize rapid conversion of network addresses and automatic discovery of devices based on the port prediction mechanism, so as to reduce communication delay and packet loss rate, thereby improving communication efficiency and stability.
[0053] See also Figure 1 As shown, an embodiment of the present invention discloses a network address translation traversal method, which is applied to a network address translation device, including:
[0054] Step S11: parsing a request packet and a response packet of a preset network protocol corresponding to the user equipment, so as to determine the information type of the network address translation information corresponding to the user equipment based on the data information obtained by parsing.
[0055] In this embodiment, it is necessary to parse the request packet of the user device and the corresponding response packet to determine the information type of the network address translation information of the user device according to the data information obtained by the parsing. Specifically, when traversing NAT, it is necessary to identify the NAT type, and the core of intelligent identification of the NAT type is to utilize the characteristics of the STUN protocol, by sending a request packet of a specific format to the public network, and analyzing the NAT type information in the returned response packet, so as to achieve accurate identification of the NAT type. Therefore, the user device can send a request packet of a preset network protocol to the NAT device using a NAT type detection algorithm, wherein the preset network protocol is the STUN protocol. If the NAT device receives the STUN request packet sent by the user device, the request packet can be parsed by the NAT type detection algorithm to determine the first data information corresponding to the STUN request packet. It should be noted that the STUN request packet contains a set of specific fields, which may be modified or retained when passing through the NAT device, and the response packet contains the actual values of these fields on the public network. It can be seen from this that it is necessary to determine the actual value of the data in the target public network corresponding to the local NAT device of the first data information, and use the actual value of the data as the second data information corresponding to the STUN response packet. It should be further explained that the NAT type detection algorithm is deployed and applied in each device that needs to interact, and is capable of sending STUN request packets, receiving and analyzing response packets, and determining the NAT type based on the response content.
[0056] Furthermore, the NAT type corresponding to the user device can be determined by analyzing the difference between the response packet and the request packet, so the first data information and the second data information can be compared. If the comparison result obtained indicates that the port number and source address corresponding to the first data information are consistent with the port number and source address corresponding to the second data information, and the second data information contains response data of different addresses, that is, it can receive responses from different IP addresses, then the NAT type is characterized as a full cone; on the other hand, if the second data information only contains response data of the same address, that is, it can only receive responses from the same IP address and port, then the NAT type is characterized as a restricted cone. In this way, the method of the present application can quickly identify the NAT type of the device, thereby improving the efficiency of network address translation traversal, that is, improving the efficiency of NAT traversal.
[0057] Step S12: input the information type into a port prediction model in a preset traversal strategy library, so as to perform port prediction based on the information type and the network address translation information through the port prediction model, and obtain a target predicted port combination corresponding to the user device, so that the user device can connect to the target public network corresponding to the network address translation device based on the target predicted port combination.
[0058] In this embodiment, when performing port prediction, it is necessary to perform port prediction based on the information type obtained by analysis, that is, the NAT type, through the port prediction model in the preset traversal policy library. Before performing port prediction, if the pre-trained model has not been trained as a port prediction model, it is necessary to train the pre-trained model and integrate the trained port prediction model into the preset traversal policy library. Specifically, it is necessary to collect a large amount of STUN protocol interaction data, and the interaction data corresponding to each user device and the preset network protocol can be collected. These data can come from actual NAT traversal scenarios, including successful and failed connection attempts. Then the interaction data is pre-processed, including removing duplicate data, processing missing values, formatting data, etc., to ensure data quality, and feature extraction is performed on the obtained pre-processed interaction data to obtain feature data corresponding to the pre-processed interaction data, and the feature data includes NAT type, source port number, target port number, connection success rate, etc. Finally, the pre-trained model is trained through the feature data to obtain the port prediction model, and the port prediction model is integrated into the preset traversal policy library. It should be noted that when training the pre-trained model, machine learning algorithms such as decision trees, neural networks, etc. can be used for model training, the model can be trained using extracted feature data, and the model performance can be evaluated through methods such as cross-validation to ensure that the model has good generalization ability and prediction accuracy.
[0059] Furthermore, when performing port prediction, it is necessary to initialize the preset traversal policy library and input the information type obtained by analysis into the port prediction model in the preset traversal policy library. After receiving the information type, the port prediction model can match the corresponding traditional NAT traversal policy in the preset traversal policy library according to the information type, such as STUN traversal policy, TURN (Traversal Using Relay NAT) traversal policy, etc. as the target network address translation traversal policy, and the target device can connect to the target public network corresponding to the network address translation device according to the determined target network address translation traversal policy. If the connection fails to be successfully connected according to the matched traversal policy, it is necessary to perform port prediction based on the information type and the network address translation information through the port prediction model. It should be noted that when performing port prediction, possible port combinations can be predicted based on the current NAT type, source port number and other information, so that the user device can connect to the target public network corresponding to the network address translation device based on the target predicted port combination.
[0060] Step S13: If the user equipment successfully connects to the target public network, the device discovery request sent by the user equipment is broadcasted, and after determining the to-be-matched device that responds to the device discovery request, the device information of the user equipment and the to-be-matched device is exchanged.
[0061] In this embodiment, if the user device successfully connects to the public network, the device discovery request sent by the user device can be broadcast to match the devices. Specifically, the device discovery request can be broadcast in the local area network through multicast UDP (User Datagram Protocol) data packets according to the mDNS protocol, and the mDNS sends multicast messages at fixed time intervals and listens for responses from other devices. However, in order to avoid the traditional mDNS sending multicast messages regardless of network fluctuations and thus causing network congestion and message conflicts, the sending interval can be automatically adjusted according to the network load to improve the efficiency of device discovery. Furthermore, since there may be multiple devices responding, it is necessary to screen and sort the received response messages to determine the target response message corresponding to the device discovery request in the response messages. Specifically, it is necessary to prioritize and quickly screen the received multicast messages, and only process messages related to the user device. And by optimizing the cache mechanism, the discovered device information can be stored in the local cache and quickly retrieved when needed to reduce unnecessary network requests and response delays. It should be noted that if the network is unstable or the device is temporarily unreachable, automatic broadcast retries, timeout detection, and error code analysis can be performed, thereby improving the efficiency and reliability of device discovery in this application.
[0062] Further, if the target response message is determined, it is necessary to determine the device to be matched corresponding to the target response message, and obtain the first device information corresponding to the user device and the second device information corresponding to the device to be matched respectively, and then send the first encrypted device information to the device to be matched, and send the second encrypted device information to the user device. It should be noted that when transmitting device information, it is necessary to perform new transmission in accordance with the defined standard device information format, and in this embodiment, the standard device information format is as follows: basic information such as IP address, port number, device type, service name, and possible advanced information such as security authentication and encryption keys. In addition, encryption technology is required to ensure the security and integrity of information when exchanging device information. Strong encryption algorithms such as AES (Advanced Encryption Standard, symmetric encryption algorithm) can be used for data encryption, and data at different levels can be encrypted such as TLS (Transport Layer Security, Transport Layer Security Protocol) and SSL (Secure Socket Layer) to protect the security of information during transmission, and verify the integrity of information through digital signatures or hash verification technologies.
[0063] Furthermore, a secure key management system needs to be established to ensure the security of key generation, distribution, storage, and destruction, and to use key exchange protocols, such as the DH (Diffie-Hellman) key exchange algorithm, to securely negotiate session keys. The two devices that establish a communication link can use HMAC (Hash-based Message Authentication Code) or similar mechanisms to verify the integrity of the data. Before sending data, the sender uses the shared key to hash the data and attach the hash value to the data. After receiving the data, the receiver uses the same key and algorithm to recalculate the hash value and compare it with the received hash value to verify whether the data is complete. For scenarios where the authenticity of the data source needs to be verified, digital signature technology can be used. The sender uses the private key to sign the data summary and sends the signature together with the data to the receiver. The receiver uses the corresponding public key to verify the validity of the signature, thereby confirming that the data is indeed from a trusted sender. In this way, the security and integrity of the data during the communication process can be effectively guaranteed.
[0064] Step S14: establishing a communication link between the user equipment and the device to be matched according to the device information, so as to perform communication between the user equipment and the device to be matched based on the communication link.
[0065] In this embodiment, it is necessary to establish a communication link between the user device and the device to be matched according to the device information. Specifically, it is necessary to configure the Internet communication protocol stack between the user device and the device to be matched, and configure the TCP / IP protocol stack to use the correct IP address and port number, so as to establish the communication link between the user device and the device to be matched based on the network address and port number in the device information through the Internet communication protocol stack. It should be noted that in order to ensure the active state of the communication link, a heartbeat packet mechanism can also be introduced to regularly detect the active state of the communication link, and if the communication link fails, a reminder notification is generated to notify the user and the corresponding maintenance personnel to restore the communication link.
[0066] It can be seen that through the method of the present application, the user device request packet and the corresponding response packet can be parsed to determine the information type of the network address translation information of the user device based on the obtained data information; the port prediction model is used to perform port prediction based on the information type and the network address translation information, so that the user device can connect to the target public network corresponding to the network address translation device based on the predicted target prediction port combination; if the connection is successful, the device discovery request sent by the user device is broadcast, and after the corresponding device to be matched is determined, the device information of the user device and the device to be matched is exchanged to establish a communication link between the user device and the device to be matched according to the device information. In this way, rapid conversion of network addresses and automatic discovery of devices can be achieved to reduce communication delays and packet loss rates, thereby improving communication efficiency and stability, and providing users with a smooth communication experience whether in a home network, enterprise network or mobile network environment.
[0067] See also Figure 2 As shown, an embodiment of the present invention discloses a network address translation traversal method, which is applied to a network address translation device, including:
[0068] Step S21: monitor in real time the communication indicators of the user equipment and the to-be-matched equipment communicating through the communication link.
[0069] In this embodiment, if it is necessary to monitor the communication between devices, key indicators in the network communication process, such as packet loss rate, delay time, bandwidth utilization, etc., can be monitored in real time, and thresholds can be set to trigger abnormal alarms when the indicators exceed the thresholds. Further, it is necessary to collect and analyze log information in the network communication process to identify potential abnormal patterns and root causes of problems. Specifically, it is necessary to establish a normal network communication behavior baseline by analyzing historical log data. The baseline includes key indicators such as communication frequency, data packet size, and communication protocol. Then, the network communication log is monitored in real time and compared with the baseline for analysis to determine which indicators are abnormal, and to analyze the malicious behavior patterns and abnormal activities corresponding to the abnormal indicators. In addition, the detected abnormal behavior can be deeply analyzed to determine its nature and scope of influence, and the source and target of the abnormal behavior can be identified to track the attack path. Finally, according to the abnormal analysis results, the root cause of the problem can be located, such as configuration errors, malware infection, etc., and the execution process and results of the response measures can be recorded to provide a reference for subsequent security decisions.
[0070] Step S22: If the communication indicator indicates that there is data packet loss, a data retransmission request is sent to a data sender through the user equipment and the data receiving direction in the to-be-matched device to retransmit data.
[0071] In this embodiment, if there is a packet loss problem caused by network congestion or equipment failure, an automatic retransmission mechanism is used to ensure the complete transmission of data. When the receiver detects data loss, it will send a retransmission request to the sender, and the sender retransmits the lost data packet according to the request. It should be noted that the retransmission waiting time can be dynamically calculated according to the network delay using an exponential backoff algorithm, and the key data in the retransmission data, such as the key frames of the video, can be given priority. For non-critical data, the retransmission can be temporarily abandoned and retransmitted when the network status is good.
[0072] Step S23: If the communication indicator indicates that the communication flow of the communication link reaches a preset flow threshold, the standby communication link between the user equipment and the to-be-matched device is enabled for load balancing.
[0073] In this embodiment, if the current communication link reaches the preset flow threshold, it indicates that the current network load is high, and a backup link can be opened for network communication between devices, and load balancing technology can be used to distribute the communication flow to multiple nodes or links to improve the stability and efficiency of communication. In this way, the stability of communication between devices can be effectively guaranteed.
[0074] In this embodiment, the communication indicators of the user device and the device to be matched through the communication link can be monitored in real time; if the communication indicator indicates that there is data packet loss, a data retransmission request is sent to the data sender through the data receiving direction in the user device and the device to be matched to retransmit the data; if the communication indicator indicates that the communication flow of the communication link reaches a preset flow threshold, the backup communication link between the user device and the device to be matched is enabled for load balancing. In this way, abnormalities in communication between devices can be effectively detected, and data can be retransmitted when abnormalities occur, and the backup link can be enabled for load balancing when necessary, thereby effectively improving the stability of communication between devices.
[0075] As a preferred embodiment, Figure 3 As shown in the figure, a modular design concept can be adopted to divide the functional modules of the technical solution into independent components or services. Each module is responsible for a specific function or business logic, and interacts and collaborates with other modules through standardized interfaces. Specifically, interface standardization can be performed to ensure smooth data exchange and communication between different modules or services. It also supports plug-in extension mechanism, allowing developers or users to develop new plug-ins or modules according to actual needs and integrate the newly developed modules into the technical solution.
[0076] It needs to be explained that if Figure 3 As shown, the description of each module in this application is as follows: the efficient and stable communication module is used to improve communication efficiency and stability, and reduce communication delays and packet loss rates by optimizing STUN and mDNS protocols to ensure smooth and reliable data transmission; the security and privacy protection module is used for data transmission security and user privacy protection, and uses encryption technology and verification mechanisms to ensure the security and integrity of data during transmission, and prevent data leakage and tampering; the widely compatible expansion module is used to support a variety of network devices, operating systems and communication protocols, and adopt a modular design concept to ensure that the solution can be easily integrated into various network environments and adapt to future technology and market changes; the low-cost and easy-to-deploy module is used to reduce deployment costs and improve ease of use, and help users get started quickly and reduce overall costs by simplifying the deployment process, reducing hardware and software requirements, and providing detailed technical documentation and usage guides; the module for promoting the development of the Internet of Things is used to realize the interconnection of various smart devices according to the NAT traversal method in this application, thereby promoting innovation and development in the fields of smart homes and smart cities.
[0077] In this way, the broad compatibility of technical solutions with existing equipment and protocols can be ensured by strictly following standards and specifications, adopting a multi-platform support strategy, establishing a comprehensive testing system, and providing detailed technical documentation and usage guides. At the same time, through modular design, interface standardization, plug-in mechanism, performance optimization and expansion, a flexible, open and easy-to-expand technical architecture is built, laying a solid foundation for future technology upgrades and functional expansions.
[0078] See also Figure 4 As shown, an embodiment of the present invention discloses a network address translation traversal method, which is applied to a network address translation device, including:
[0079] An information type determination module 11 is used to parse a request packet and a response packet of a preset network protocol corresponding to a user device, so as to determine the information type of the network address translation information corresponding to the user device based on the data information obtained by the parsing;
[0080] The local area network connection module 12 is used to input the information type into the port prediction model in the preset traversal strategy library, so as to perform port prediction based on the information type and the network address translation information through the port prediction model, and obtain a target predicted port combination corresponding to the user device, so that the user device can connect to the target public network corresponding to the network address translation device based on the target predicted port combination;
[0081] An information exchange module 13 is used to broadcast the device discovery request sent by the user equipment if the user equipment successfully connects to the target public network, and after determining the to-be-matched device that responds to the device discovery request, exchange device information of the user equipment and the to-be-matched device;
[0082] The communication link establishing module 14 is used to establish a communication link between the user equipment and the device to be matched according to the device information, so as to perform communication between the user equipment and the device to be matched based on the communication link.
[0083] In the present application, the request packet and response packet of the preset network protocol corresponding to the user device can be parsed to determine the information type of the network address translation information corresponding to the user device based on the data information obtained by the analysis; the information type is input into the port prediction model in the preset traversal policy library to perform port prediction based on the information type and the network address translation information through the port prediction model to obtain the target predicted port combination corresponding to the user device, so that the user device can connect to the target public network corresponding to the network address translation device based on the target predicted port combination; if the user device successfully connects to the target public network, the device discovery request sent by the user device is broadcast, and after determining the device to be matched that responds to the device discovery request, the device information of the user device and the device to be matched is exchanged; a communication link between the user device and the device to be matched is established based on the device information, so as to communicate between the user device and the device to be matched based on the communication link. It can be seen that through the method of the present application, the user device request packet and the corresponding response packet can be parsed to determine the information type of the network address translation information of the user device based on the obtained data information; the port prediction model is used to perform port prediction based on the information type and the network address translation information, so that the user device can connect to the target public network corresponding to the network address translation device based on the predicted target prediction port combination; if the connection is successful, the device discovery request sent by the user device is broadcast, and after the corresponding device to be matched is determined, the device information of the user device and the device to be matched is exchanged to establish a communication link between the user device and the device to be matched according to the device information. In this way, rapid conversion of network addresses and automatic discovery of devices can be achieved to reduce communication delays and packet loss rates, thereby improving communication efficiency and stability, and providing users with a smooth communication experience whether in a home network, enterprise network or mobile network environment.
[0084] In some embodiments, the information type determination module 11 may specifically include:
[0085] A request parsing unit, configured to parse a request packet of a preset network protocol sent by a user device to determine first data information corresponding to the request packet of the preset network protocol if the request packet is received;
[0086] An information determination unit, configured to determine an actual value of data in a target public network corresponding to the local portion of the first data information, and use the actual value of the data as second data information corresponding to a response packet of a preset network protocol;
[0087] a first data type determination unit, configured to compare the first data information and the second data information, and if the comparison result indicates that the port number and source address corresponding to the first data information are consistent with the port number and source address corresponding to the second data information, and the second data information includes response data of different addresses, then determining that the information type of the network address translation information corresponding to the user equipment is full cone;
[0088] The second data type determining unit is configured to determine that the information type of the network address translation information corresponding to the user equipment is a restricted cone if the second data information only includes response data of the same address.
[0089] In some embodiments, the network address translation traversal device may further include:
[0090] A data collection unit, used to collect interaction data corresponding to each user device and the preset network protocol; the interaction data includes data in a request packet and a response packet corresponding to each user data and a connection success rate corresponding to each user device;
[0091] A data preprocessing unit, used to preprocess the interaction data and perform feature extraction on the obtained preprocessed interaction data to obtain feature data corresponding to the preprocessed interaction data;
[0092] The model integration unit is used to train the pre-trained model through the feature data to obtain a port prediction model, and integrate the port prediction model into a preset traversal strategy library.
[0093] In some embodiments, the local area network connection module 12 may specifically include:
[0094] A policy matching unit, used for initializing a preset traversal policy library, and inputting the information type into a port prediction model in the preset traversal policy library, so as to match a corresponding target network address translation traversal policy in the preset traversal policy library based on the information type through the port prediction model, so that the user device is connected to a target public network corresponding to the network address translation device based on the target network address translation traversal policy;
[0095] A port prediction unit is used to perform port prediction based on the information type and the network address translation information through the port prediction model if the user device fails to connect to the target public network corresponding to the network address translation device based on the target network address translation traversal strategy, so as to obtain a target predicted port combination corresponding to the user device.
[0096] In some embodiments, the information exchange module 13 may specifically include:
[0097] a request broadcast unit, configured to broadcast the device discovery request sent by the user equipment, and screen and sort the received response messages to determine a target response message corresponding to the device discovery request among the response messages;
[0098] A device information acquisition unit, used to determine the to-be-matched device corresponding to the target response message, and respectively acquire first device information corresponding to the user device and second device information corresponding to the to-be-matched device;
[0099] an information encryption unit, configured to encrypt the first device information and the second device information respectively by using a preset encryption algorithm to obtain first encrypted device information corresponding to the first device information and second encrypted device information corresponding to the second device information;
[0100] The device information sending unit is used to send the first encrypted device information to the to-be-matched device, and send the second encrypted device information to the user device.
[0101] In some embodiments, the communication link establishing module 14 may specifically include:
[0102] A communication establishing unit is used to configure an Internet communication protocol stack between the user device and the device to be matched, so as to establish a communication link between the user device and the device to be matched based on the network address and port number in the device information through the Internet communication protocol stack.
[0103] In some embodiments, the network address translation traversal device may further include:
[0104] A communication monitoring unit, used for monitoring in real time the communication indicators of the user equipment and the to-be-matched equipment communicating through the communication link;
[0105] A data retransmission unit, configured to send a data retransmission request to a data sender through the user equipment and a data receiving direction in the to-be-matched device to retransmit data if the communication indicator indicates that data packet loss exists;
[0106] The standby link enabling unit is used to enable the standby communication link between the user equipment and the to-be-matched device for load balancing if the communication indicator indicates that the communication flow of the communication link reaches a preset flow threshold.
[0107] Furthermore, the present application also discloses an electronic device. Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.
[0108] Figure 5 A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the network address translation traversal method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0109] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0110] In addition, the memory 22 as a carrier for resource storage may be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon may include an operating system 221, a computer program 222, etc., and the storage method may be temporary storage or permanent storage.
[0111] The operating system 221 is used to manage and control the hardware devices and computer programs 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the network address translation traversal method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.
[0112] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein the computer program, when executed by a processor, implements the aforementioned disclosed network address translation traversal method. For the specific steps of the method, reference may be made to the corresponding contents disclosed in the aforementioned embodiments, and no further description will be given here.
[0113] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0114] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0115] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0116] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0117] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A network address translation traversal method, characterized in that: Applicable to network address translation devices, including: Parsing a request packet and a response packet of a preset network protocol corresponding to the user equipment, so as to determine the information type of the network address translation information corresponding to the user equipment based on the data information obtained by the parsing; Input the information type into a port prediction model in a preset traversal strategy library, so as to perform port prediction based on the information type and the network address translation information through the port prediction model, and obtain a target predicted port combination corresponding to the user device, so that the user device can connect to the target public network corresponding to the network address translation device based on the target predicted port combination; If the user equipment successfully connects to the target public network, broadcasting the device discovery request sent by the user equipment, and after determining the to-be-matched device that responds to the device discovery request, exchanging device information of the user equipment and the to-be-matched device; A communication link is established between the user equipment and the device to be matched according to the device information, so as to perform communication between the user equipment and the device to be matched based on the communication link.
2. The network address translation traversal method according to claim 1, characterized in that: The parsing of the request packet and the response packet of the preset network protocol corresponding to the user equipment to determine the information type of the network address translation information corresponding to the user equipment based on the parsed data information includes: If a request packet of a preset network protocol sent by a user device is received, the request packet is parsed to determine first data information corresponding to the request packet of the preset network protocol; Determine the actual value of the data in the target public network corresponding to the local data information, and use the actual value of the data as the second data information corresponding to the response packet of the preset network protocol; Comparing the first data information and the second data information, if the comparison result indicates that the port number and source address corresponding to the first data information are consistent with the port number and source address corresponding to the second data information, and the second data information includes response data of different addresses, then determining that the information type of the network address translation information corresponding to the user equipment is full cone; If the second data information only includes response data of the same address, it is determined that the information type of the network address translation information corresponding to the user equipment is a restricted cone.
3. The network address translation traversal method according to claim 1, characterized in that: The method further includes: inputting the information type into a port prediction model in a preset traversal strategy library, performing port prediction based on the information type and the network address translation information through the port prediction model, and obtaining a target predicted port combination corresponding to the user device, so that the user device can connect to the target public network corresponding to the network address translation device based on the target predicted port combination. Collecting interaction data corresponding to each user device and the preset network protocol; the interaction data includes data in a request packet and a response packet corresponding to each user data and a connection success rate corresponding to each user device; Preprocessing the interaction data, and performing feature extraction on the obtained preprocessed interaction data to obtain feature data corresponding to the preprocessed interaction data; The pre-trained model is trained by the feature data to obtain a port prediction model, and the port prediction model is integrated into a preset traversal strategy library.
4. The network address translation traversal method according to claim 1, characterized in that: The step of inputting the information type into a port prediction model in a preset traversal strategy library, so as to perform port prediction based on the information type and the network address translation information through the port prediction model to obtain a target predicted port combination corresponding to the user equipment, comprises: Initialize a preset traversal policy library, and input the information type into a port prediction model in the preset traversal policy library, so as to match a corresponding target network address translation traversal policy in the preset traversal policy library based on the information type through the port prediction model, so that the user device connects to the target public network corresponding to the network address translation device based on the target network address translation traversal policy; If the user device fails to connect to the target public network corresponding to the network address translation device based on the target network address translation traversal strategy, port prediction is performed based on the information type and the network address translation information through the port prediction model to obtain a target predicted port combination corresponding to the user device.
5. The network address translation traversal method according to claim 1, characterized in that: The broadcasting of the device discovery request sent by the user equipment and, after determining a to-be-matched device that responds to the device discovery request, exchanging device information of the user equipment and the to-be-matched device, includes: Broadcasting the device discovery request sent by the user equipment, and screening and sorting the received response messages to determine a target response message corresponding to the device discovery request among the response messages; Determine the to-be-matched device corresponding to the target response message, and respectively obtain first device information corresponding to the user equipment and second device information corresponding to the to-be-matched device; Encrypting the first device information and the second device information respectively by a preset encryption algorithm to obtain first encrypted device information corresponding to the first device information and second encrypted device information corresponding to the second device information; The first encrypted device information is sent to the device to be matched, and the second encrypted device information is sent to the user device.
6. The network address translation traversal method according to claim 1, characterized in that: The establishing a communication link between the user equipment and the to-be-matched equipment according to the equipment information includes: An Internet communication protocol stack is configured between the user device and the device to be matched, so as to establish a communication link between the user device and the device to be matched based on the network address and port number in the device information through the Internet communication protocol stack.
7. The network address translation traversal method according to any one of claims 1 to 6, characterized in that: Also includes: Real-time monitoring of communication indicators of the user equipment and the to-be-matched equipment communicating through the communication link; If the communication indicator indicates that there is data packet loss, a data retransmission request is sent to the data sender through the user equipment and the data receiving direction in the to-be-matched device to re-transmit the data; If the communication indicator indicates that the communication flow of the communication link reaches a preset flow threshold, a standby communication link between the user equipment and the device to be matched is enabled for load balancing.
8. A network address translation traversal device, characterized in that: Applicable to network address translation devices, including: An information type determination module, used to parse a request packet and a response packet of a preset network protocol corresponding to a user device, so as to determine the information type of the network address translation information corresponding to the user device based on the data information obtained by the parsing; A local area network connection module, used for inputting the information type into a port prediction model in a preset traversal strategy library, so as to perform port prediction based on the information type and the network address translation information through the port prediction model, and obtain a target predicted port combination corresponding to the user device, so that the user device can connect to the target public network corresponding to the network address translation device based on the target predicted port combination; An information exchange module, configured to broadcast a device discovery request sent by the user equipment if the user equipment successfully connects to the target public network, and exchange device information of the user equipment and the device to be matched after determining a device to be matched that responds to the device discovery request; The communication link establishing module is used to establish a communication link between the user equipment and the device to be matched according to the device information, so as to perform communication between the user equipment and the device to be matched based on the communication link.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the network address translation traversal method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the network address translation traversal method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Symmetrical NAT traversal method and system based on big data analysis
CN105141711A
Method and device for realizing symmetric NAT (Network Address Translation) traversal and computer equipment
CN113132507A
Network address translation type detection method and system and electronic equipment
CN115766654A
Method and apparatus for implementing network communication through NAT
CN1863157A
Method and apparatus for provisioning network address translator traversal methods
US20130124735A1