CN105979022B - NAT (network Address translation) penetrating method and system based on UPnP (Universal plug and Play) protocol - Google Patents
NAT (network Address translation) penetrating method and system based on UPnP (Universal plug and Play) protocol Download PDFInfo
- Publication number
- CN105979022B CN105979022B CN201610278924.7A CN201610278924A CN105979022B CN 105979022 B CN105979022 B CN 105979022B CN 201610278924 A CN201610278924 A CN 201610278924A CN 105979022 B CN105979022 B CN 105979022B
- Authority
- CN
- China
- Prior art keywords
- port
- mapping
- request
- port mapping
- gateway equipment
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L61/00—Network arrangements, protocols or services for addressing or naming
- H04L61/09—Mapping addresses
- H04L61/25—Mapping addresses of the same type
- H04L61/2503—Translation of Internet protocol [IP] addresses
- H04L61/256—NAT traversal
- H04L61/2582—NAT traversal through control of the NAT server, e.g. using universal plug and play [UPnP]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L61/00—Network arrangements, protocols or services for addressing or naming
- H04L61/09—Mapping addresses
- H04L61/25—Mapping addresses of the same type
- H04L61/2503—Translation of Internet protocol [IP] addresses
- H04L61/256—NAT traversal
- H04L61/2585—NAT traversal through application level gateway [ALG]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/104—Peer-to-peer [P2P] networks
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The invention provides a UPnP protocol-based NAT penetration method and a UPnP protocol-based NAT penetration system, and relates to the technical field of network communication. The method comprises the following steps: when a terminal starts a UPnP service, searching gateway equipment supporting a UPnP protocol in a local area network; monitoring a port adding mapping request sent by an application program, and adding port mapping on gateway equipment according to the monitored port adding mapping request; uploading the successfully added port mapping information to a P2P cloud server, so that other network applications can acquire the port mapping information from the P2P cloud server to realize data communication with an application program. According to the invention, the port mapping can be automatically added on the gateway equipment through the UPnP service, manual configuration of a user is not required, NAT penetration is not required to be assisted by a third-party agent, the penetration rate of the home network P2P can be optimized, and the experience of the user is improved.
Description
Technical Field
The invention belongs to the technical field of network communication, and particularly relates to a Network Address Translation (NAT) penetration method and system based on a Universal Plug and play (UPnP) protocol.
Background
With the increasing computer performance and the development of network technology, the dominance of the client-server communication mode in the internet has been broken, and the P2P (peer-to-peer) communication mode is used by more and more network applications, and in the P2P communication mode, the hosts can directly communicate with each other to realize resource sharing and information exchange, which provides greater convenience for communication and exchange among users. P2P is also called peer-to-peer connection or peer-to-peer network, in which the roles of all communication nodes are equal, each node plays the dual roles of client and server, and the sharing of resources such as file information, processor budget capability and storage space is realized by direct communication between nodes.
However, in the current Ipv4 network environment, the widespread presence of NAT devices due to network address starvation makes it difficult for hosts in different internal private networks to communicate directly, which greatly limits the application and development of P2P. NAT is a technology for translating private IP addresses of an internal network to public IP addresses of an external network, allowing multiple hosts in an organization to share an Internet connection, with one or a few public IP addresses connecting to the Internet. The existence of NAT presents an obstacle to communication between hosts in different intranets. The NAT traversal technology is a technology that enables internet to be implemented between hosts in different internal networks by adopting certain technical measures. Therefore, to implement P2P communication between hosts in different intranets, the problem of NAT traversal must be solved to some extent, otherwise the system will not work properly.
At present, most of the home networks in P2P cannot achieve NAT traversal well, because most of the home networks employ symmetric NAT devices, so that P2P must assist NAT traversal by means of a third-party agent or require a user to add port mapping for a specific service on the symmetric NAT device, and these two drawbacks of achieving NAT traversal are: when the data transmitted by the P2P is forwarded by a third-party agent, the delay and the possibility of packet loss of the data packet are increased, and meanwhile, the overhead of system deployment is also increased; adding port mapping for a specific service on the symmetric NAT device requires a user to manually configure the symmetric NAT device, requires the user to know a certain expertise, and is very inconvenient to operate. Therefore, how to achieve good NAT traversal in the symmetric NAT device of the home network has become an urgent problem to be solved by each P2P application service operator.
Disclosure of Invention
An embodiment of the present invention aims to provide a method and a system for NAT traversal based on a UPnP protocol, and aims to solve the problem that in the prior art, a P2P application cannot achieve good NAT traversal in a symmetric NAT device of a home network.
The embodiment of the invention is realized in such a way that an NAT (network address translation) penetrating method based on a UPnP (Universal plug and Play) protocol comprises the following steps:
when a terminal starts a UPnP service, searching gateway equipment supporting a UPnP protocol in a local area network;
monitoring an adding port mapping request sent by an application program, and adding port mapping on the gateway equipment according to the monitored adding port mapping request;
uploading the successfully added port mapping information to a P2P cloud server, so that other network applications can acquire the port mapping information from the P2P cloud server to realize data communication with the application program.
In the UPNP traversal method based on the UPNP protocol according to the embodiment of the present invention, the monitoring a port addition mapping request sent by an application program, and adding port mapping on the gateway device according to the port addition mapping request specifically includes:
monitoring an adding port mapping request sent by an application program through an Aidl interface or Intent, wherein the adding port mapping request at least comprises an internal port, an internal IP address and a protocol type;
judging whether the monitored data format and data type of the port adding mapping request conform to the predefined data format and data type;
if yes, adding the port adding mapping request into a linked list and marking the port adding mapping request as a port adding mapping request to be processed;
and reading the port adding mapping request to be processed in the linked list, and adding port mapping on the gateway equipment according to the port adding mapping request to be processed.
In the NAT traversal method based on the UPnP protocol according to the embodiment of the present invention, reading the to-be-processed add port mapping request in the linked list, and adding port mapping on the gateway device according to the to-be-processed add port mapping request specifically includes:
acquiring the dialing type of the gateway equipment;
judging whether the UPnP service of the gateway equipment is normal or not;
if the UPnP service of the gateway equipment is normal, reading a mapping request of an adding port to be processed in the linked list;
adding port mapping on the gateway equipment according to the to-be-processed port mapping adding request and the dialing type of the gateway equipment;
and receiving prompt information which is returned by the gateway equipment and indicates whether the added port mapping is successful, and executing corresponding operation according to the prompt information.
In the UPnP protocol-based NAT traversal method according to the embodiment of the present invention, the adding port mapping on the gateway device according to the to-be-processed port-adding mapping request and the dialing type of the gateway device specifically includes:
acquiring an added port mapping rule on the gateway equipment according to the to-be-processed port adding mapping request and the dialing type of the gateway equipment, and storing the added port mapping rule by using a hash array;
inquiring whether the same port mapping rule exists in the hash array or not according to the to-be-processed adding port mapping request, wherein the to-be-processed adding port mapping request at least comprises an internal port, an internal IP address and a protocol type;
if the same port mapping rule exists, acquiring an external port corresponding to the internal port in the port mapping rule so as to complete adding port mapping on the gateway equipment;
if the same port mapping rule does not exist, judging whether the to-be-processed adding port mapping request designates an external port or not;
if an external port is appointed, directly sending a request for adding port mapping to the gateway equipment, wherein the request comprises an internal IP address, an internal port, the external port, a protocol type and effective time, and enabling the gateway equipment to automatically add the port mapping according to the request;
if the external port is not appointed, setting the external port as the current maximum external port value in the hash array plus 1, and sending a request for adding port mapping to the gateway equipment, so that the gateway equipment automatically adds the port mapping according to the request.
In the NAT traversal method based on the UPnP protocol according to the embodiment of the present invention, the receiving a prompt message indicating whether the mapping of the added port returned by the gateway device is successful, and executing corresponding operations according to the prompt message specifically includes:
if prompt information of successful port adding mapping returned by the gateway equipment is received, marking a port adding mapping request to be processed in the linked list as being successfully added, and uploading the successfully added port mapping information to a P2P cloud server;
and if the prompt information of the addition port mapping failure returned by the gateway equipment is received, marking the to-be-processed addition port mapping request in the linked list as the addition failure.
Another object of an embodiment of the present invention is to provide a NAT traversal system based on a UPnP protocol, including:
the gateway equipment searching module is used for searching gateway equipment supporting a UPNP protocol in a local area network when the terminal starts the UPnP service;
the port mapping processing module is used for monitoring a port adding mapping request sent by an application program and adding port mapping on the gateway equipment according to the monitored port adding mapping request;
and the uploading module is used for uploading the successfully added port mapping information to the P2P cloud server, so that other network applications can acquire the port mapping information from the P2P cloud server to realize data communication with the application program.
In the UPnP protocol-based NAT traversal system according to the embodiment of the present invention, the port mapping processing module specifically includes:
the monitoring unit is used for monitoring an adding port mapping request sent by an application program through an Aidl interface or Intent, wherein the adding port mapping request at least comprises an internal port, an internal IP address and a protocol type;
the judging unit is used for judging whether the monitored data format and data type of the adding port mapping request conform to the predefined data format and data type;
the linked list processing unit is used for adding the port adding mapping request into the linked list and marking the port adding mapping request as a port adding mapping request to be processed if the port adding mapping request is consistent with the port adding mapping request;
and the port mapping processing unit is used for reading the port mapping request to be processed in the linked list and adding port mapping on the gateway equipment according to the port mapping request to be processed.
In the UPnP protocol-based NAT traversal system according to the embodiment of the present invention, the port mapping processing unit specifically includes:
a dialing type obtaining subunit, configured to obtain a dialing type of the gateway device;
a UPnP service judging subunit, configured to judge whether a UPnP service of the gateway device is normal;
a port mapping request reading subunit, configured to read, if the UPnP service of the gateway device is normal, a to-be-processed port mapping request to be added in the linked list;
a port mapping processing subunit, configured to add port mapping on the gateway device according to the to-be-processed port-added mapping request and the dialing type of the gateway device;
and the prompting subunit is used for receiving the prompting information which is returned by the gateway device and indicates whether the mapping of the added port is successful or not, and executing corresponding operation according to the prompting information.
In the UPnP protocol-based NAT traversal system according to the embodiment of the present invention, the port mapping processing subunit is specifically configured to:
acquiring an added port mapping rule on the gateway equipment according to the to-be-processed port adding mapping request and the dialing type of the gateway equipment, and storing the added port mapping rule by using a hash array;
inquiring whether the same port mapping rule exists in the hash array or not according to the to-be-processed adding port mapping request, wherein the to-be-processed adding port mapping request at least comprises an internal port, an internal IP address and a protocol type;
if the same port mapping rule exists, acquiring an external port corresponding to the internal port in the port mapping rule so as to complete adding port mapping on the gateway equipment;
if the same port mapping rule does not exist, judging whether the to-be-processed adding port mapping request designates an external port or not;
if an external port is appointed, directly sending a request for adding port mapping to the gateway equipment, wherein the request comprises an internal IP address, an internal port, the external port, a protocol type and effective time, and enabling the gateway equipment to automatically add the port mapping according to the request;
if the external port is not appointed, setting the external port as the current maximum external port value in the hash array plus 1, and sending a request for adding port mapping to the gateway equipment, so that the gateway equipment automatically adds the port mapping according to the request.
In the UPnP protocol-based NAT traversal system according to the embodiment of the present invention, the prompting subunit is specifically configured to:
if prompt information of successful port adding mapping returned by the gateway equipment is received, marking a port adding mapping request to be processed in the linked list as being successfully added, and controlling the uploading module to upload the successfully added port mapping information to the P2P cloud server;
and if the prompt information of the addition port mapping failure returned by the gateway equipment is received, marking the to-be-processed addition port mapping request in the linked list as the addition failure.
The UPnP-based NAT traversal method and the UPnP-based NAT traversal system provided by the embodiment of the invention have the following beneficial effects that:
in the embodiment of the invention, when the terminal starts the UPnP service, the gateway equipment supporting the UPnP protocol is searched in the local area network; monitoring an adding port mapping request sent by an application program, and adding port mapping on the gateway equipment according to the monitored adding port mapping request; and finally, uploading the port mapping information which is successfully added to a P2P cloud server, so that other network applications can acquire the port mapping information from the P2P cloud server to realize data communication with the application program, thereby automatically adding port mapping on gateway equipment through UPnP service, without manual configuration of a user or NAT penetration assisted by a third party agent, optimizing the penetration rate of the home network P2P, and improving the experience of the user.
Drawings
Fig. 1 is a flowchart of a specific implementation of a UPnP protocol-based NAT traversal method according to an embodiment of the present invention;
fig. 2 is a flowchart of a specific implementation of step S101 in a UPnP protocol-based NAT traversal method according to an embodiment of the present invention;
fig. 3 is a flowchart of a specific implementation of step S102 in a UPnP protocol-based NAT traversal method according to an embodiment of the present invention;
fig. 4 is a flowchart of a specific implementation of step S305 in a UPnP protocol-based NAT traversal method according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a NAT traversal system based on a UPnP protocol according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Fig. 1 is a flowchart of a specific implementation of a UPnP protocol-based NAT traversal method according to an embodiment of the present invention. Referring to fig. 1, a NAT traversal method based on a UPnP protocol provided in this embodiment includes:
in S101, when the terminal starts the UPnP service, a gateway device supporting the UPnP protocol is searched in the local area network.
In this embodiment, when the terminal is started, a UPnP service is created and started, and a gateway device supporting the UPnP protocol is searched in a local area network where the terminal is located through the UPnP service.
In S102, a port mapping adding request sent by an application program is monitored, and port mapping is added to the gateway device according to the monitored port mapping adding request.
Fig. 2 shows a specific implementation flow of S102, and referring to fig. 2, S102 specifically includes:
in S201, an add port mapping request sent by an application program is received through an Aidl interface or Intent, where the add port mapping request at least includes an internal port, an internal IP address, and a protocol type;
in S202, determining whether the data format and the data type of the add port mapping request conform to the predefined data format and data type, if so, entering step S203, and if not, entering step S205;
in S203, adding the add port mapping request to a linked list and marking as a pending add port mapping request;
in S204, reading a to-be-processed adding port mapping request in the linked list, and adding port mapping on the gateway equipment according to the to-be-processed adding port mapping request;
in S205, the received prompt message indicating that the add port mapping request is verified incorrectly is returned to the application program, and the process is ended.
In this embodiment of the present invention, S203 may further include a prompt message that the verification of the received add port mapping request is successful is returned to the application program, specifically, when the data format and the data type of the add port mapping request conform to the predefined data format and data type, a prompt code with correct parameters is returned to the application program: 0, adding the port adding mapping request into a linked list and marking as a port adding mapping request to be processed, and entering the step S102; otherwise, when the data format and/or the data type of the addition mapping request do not conform to the predefined data format and data type, a prompt code of parameter error is returned to the application program: 100, and ends the flow.
Fig. 3 shows a specific implementation flow of S204, and referring to fig. 3, S204 specifically includes:
in S301, a dialing type of the gateway device is acquired;
in S302, determining whether the UPnP service of the gateway device is normal, if so, entering step S303, and if not, returning to step S301;
in S303, reading a mapping request of an adding port to be processed in the linked list;
in S304, adding port mapping on the gateway device according to the to-be-processed port mapping adding request and the dialing type of the gateway device;
in S305, a prompt message indicating whether the mapping of the added port returned by the gateway device is successful is received, and a corresponding operation is executed according to the prompt message.
In this embodiment of the present invention, the gateway device is a symmetric NAT device, and the determining whether the UPnP service of the gateway device is normal mainly determines whether the UPnP service of the gateway device is closed, specifically: when ssdp of the searched gateway device is byebye, the closing of the UPnP service of the gateway device is described, and the abnormal UPnP service of the gateway device is described at the moment; and when the ssdp of the searched gateway device is alive, the gateway device is indicated that the UPnP service is started, and the UPnP service of the gateway device is normal. Further, the dialing types of the gateway device include PPPOE, L2TP, and PPTP. Further, fig. 4 shows a specific implementation flow of S305, and referring to fig. 4, S304 specifically includes:
in S401, acquiring an added port mapping rule on the gateway device according to the to-be-processed port adding mapping request and the dialing type of the gateway device, and storing the added port mapping rule in a hash array;
in S402, querying whether the same port mapping rule exists in the hash array according to the to-be-processed port-added mapping request, if so, entering step S403, and if not, entering step S404;
in S403, obtaining an external port corresponding to the internal port in the port mapping rule, so as to complete adding port mapping on the gateway device;
in S404, determining whether the to-be-processed add port mapping request specifies an external port, if not, entering step S405, and if so, entering step S406;
in S405, setting an external port as the current maximum external port value in the hash array plus 1;
in S406, a request for adding a port mapping is sent to the gateway device, so that the gateway device automatically adds the port mapping according to the request, where the request includes an internal IP address, an internal port, an external port, a protocol type, and validation time, and the gateway device automatically adds the port mapping according to the request.
In this embodiment, the to-be-processed add port mapping request includes an internal port, an internal IP address, and a protocol type, and in step S402, it is mainly determined whether there is a mapping rule that is the same as the internal port number, the internal IP address, and the protocol type carried in the add mapping request, and if the same mapping rule is found, an external port corresponding to the internal port in the found mapping rule is directly read as an externally issued port of the application, and the process of adding port mapping is ended; otherwise, if the same mapping rule is not found, the process proceeds to step S404. It should be noted that, in other embodiments, the add port mapping request may further include a designated external port, and when the add port mapping request includes the designated external port, in step S402, it may also be determined whether the designated external port is occupied by another internal port by querying the hash array, and the external port designated in the add port request is deleted when occupied by another port, and step S406 is performed, and the gateway device automatically allocates an external port to the internal port in the add port mapping request; otherwise, if the external port is not occupied, step S405 is performed, and a request for adding port mapping is directly sent to the gateway device. In addition, when the add port mapping request in the embodiment of the present invention does not include an internal IP address, the IP address of the device that receives the add port mapping request sent by the application program is obtained as an intranet IP address.
Further, in the embodiment of the present invention, step S305 specifically includes: if the prompt information of successful port adding mapping returned by the gateway device is received, marking the port adding mapping request to be processed in the linked list as being successfully added, and entering the step S103 to upload the successfully added port mapping information to the P2P cloud server; and if the prompt information of the addition port mapping failure returned by the gateway equipment is received, marking the to-be-processed addition port mapping request in the linked list as the addition failure, and ending the process.
In S103, uploading the successfully added port mapping information to a P2P cloud server, so that other network applications obtain the port mapping information from the P2P cloud server, and implement data communication with the application program.
Further, in this embodiment of the present invention, after adding the port mapping information that is successfully added to the P2P cloud server, the adding may further include: judging whether the gateway equipment fails, if so, deleting all port mapping rules stored in the P2P cloud server, and marking all port mapping requests to be processed in a linked list as failed addition; if the gateway equipment operates normally, whether the IP address of the WAN port of the gateway equipment changes or not is judged, if not, other port adding mapping requests are continuously processed, and if so, all relevant recorded extranet IP address information in the P2P cloud server is updated.
As can be seen from the above, in the NAT traversal method based on the UPnP protocol provided in the embodiment of the present invention, when the UPnP service is started at the terminal, a gateway device supporting the UPnP protocol is searched in the local area network; monitoring an adding port mapping request sent by an application program, and adding port mapping on the gateway equipment according to the monitored adding port mapping request; and finally, the port mapping information which is successfully added is uploaded to a P2P cloud server, so that other network applications can acquire the port mapping information from the P2P cloud server to realize data communication with the application program, the port mapping can be automatically added to the gateway equipment through UPnP service, manual configuration of a user is not needed, NAT penetration is not needed to be assisted by a third party agent, the gateway equipment in the home network can realize good NAT penetration, the penetration rate of the home network P2P is optimized, and the experience of the user is improved.
Fig. 5 is a schematic structural diagram of a UPnP protocol-based NAT traversal system located in a terminal where an application is located, and configured to execute the methods provided in the embodiments shown in fig. 1 to fig. 4. Only the portions related to the present embodiment are shown for convenience of explanation.
Referring to fig. 5, the present embodiment provides a NAT traversal system based on a UPnP protocol, including:
the gateway equipment searching module 1 is used for searching gateway equipment supporting a UPnP protocol in a local area network when a terminal starts a UPnP service;
the port mapping processing module 2 is configured to monitor a port mapping adding request sent by an application program, and add port mapping on the gateway device according to the monitored port mapping adding request;
and the uploading module 3 is configured to upload the successfully added port mapping information to a P2P cloud server, so that other network applications acquire the port mapping information from the P2P cloud server, and implement data communication with the application program.
Further, the port mapping processing module 2 specifically includes:
a monitoring unit 21, configured to monitor an add port mapping request sent by an application program through an Aidl interface or Intent, where the add port mapping request at least includes an internal port, an internal IP address, and a protocol type;
a judging unit 22, configured to judge whether the monitored data format and data type of the add port mapping request conform to a predefined data format and data type;
a linked list processing unit 23, configured to add the port mapping request to a linked list and mark the port mapping request as a to-be-processed port mapping request if the port mapping request matches the linked list;
and the port mapping processing unit 24 is configured to read the to-be-processed port adding mapping request in the linked list, and add port mapping on the gateway device according to the to-be-processed port adding mapping request.
Further, the port mapping processing unit 24 specifically includes:
a dialing type obtaining subunit 241, configured to obtain a dialing type of the gateway device;
a UPnP service determination subunit 242, configured to determine whether a UPnP service of the gateway device is normal;
a port mapping request reading subunit 243, configured to read, if the UPnP service of the gateway device is normal, a to-be-processed port mapping request to be added in the linked list;
a port mapping processing subunit 244, configured to add port mapping on the gateway device according to the to-be-processed port mapping adding request and the dialing type of the gateway device;
and the prompt subunit 245 is configured to receive a prompt message that is returned by the gateway device and indicates whether the mapping of the added port is successful, and execute a corresponding operation according to the prompt message.
Further, the port mapping processing subunit 244 is specifically configured to:
acquiring an added port mapping rule on the gateway equipment according to the to-be-processed port adding mapping request and the dialing type of the gateway equipment, and storing the added port mapping rule by using a hash array;
inquiring whether the same port mapping rule exists in the hash array or not according to the to-be-processed adding port mapping request, wherein the to-be-processed adding port mapping request at least comprises an internal port, an internal IP address and a protocol type;
if the same port mapping rule exists, acquiring an external port corresponding to the internal port in the port mapping rule so as to complete adding port mapping on the gateway equipment;
if the same port mapping rule does not exist, judging whether the to-be-processed adding port mapping request designates an external port or not;
if an external port is appointed, directly sending a request for adding port mapping to the gateway equipment, wherein the request comprises an internal IP address, an internal port, the external port, a protocol type and effective time, and enabling the gateway equipment to automatically add the port mapping according to the request;
if the external port is not appointed, setting the external port as the current maximum external port value in the hash array plus 1, and sending a request for adding port mapping to the gateway equipment, so that the gateway equipment automatically adds the port mapping according to the request.
Further, the prompt subunit 245 is specifically configured to:
if prompt information of successful port adding mapping returned by the gateway equipment is received, marking a port adding mapping request to be processed in the linked list as being successfully added, and controlling the uploading module to upload the successfully added port mapping information to the P2P cloud server;
and if the prompt information of the addition port mapping failure returned by the gateway equipment is received, marking the to-be-processed addition port mapping request in the linked list as the addition failure.
It should be noted that, since each module in the system provided in the embodiment of the present invention is based on the same concept as that of the embodiment of the method of the present invention, the technical effect brought by the embodiment of the method of the present invention is the same as that of the embodiment of the method of the present invention, and specific contents may be referred to the description in the embodiment of the method of the present invention, and are not described herein again.
Therefore, it can be seen that the UPnP protocol-based NAT traversal system provided in the embodiment of the present invention also starts the UPnP service first, and searches for a gateway device supporting the UPnP protocol in the local area network; monitoring an adding port mapping request sent by an application program, and adding port mapping on the gateway equipment according to the monitored adding port mapping request; and finally, the port mapping information which is successfully added is uploaded to a P2P cloud server, so that other network applications can acquire the port mapping information from the P2P cloud server to realize data communication with the application program, the port mapping can be automatically added to the gateway equipment through UPnP service, manual configuration of a user is not needed, NAT penetration is not needed to be assisted by a third party agent, the gateway equipment in the home network can realize good NAT penetration, the penetration rate of the home network P2P can be optimized, and the experience of the user is improved.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents and improvements made within the spirit and principle of the present invention are intended to be included within the scope of the present invention.
Claims (10)
1. A NAT traversal method based on UPnP protocol is characterized by comprising the following steps:
when a terminal starts a UPnP service, searching gateway equipment supporting a UPnP protocol in a local area network where the terminal is located;
monitoring an adding port mapping request sent by an application program, and adding port mapping on the gateway equipment according to the monitored adding port mapping request;
uploading the successfully added port mapping information to a P2P cloud server, so that other network applications can acquire the port mapping information from the P2P cloud server to realize data communication with the application program.
2. The UPnP protocol-based NAT traversal method according to claim 1, wherein the monitoring of the port mapping addition request sent by the application program, and the adding of the port mapping on the gateway device according to the port mapping addition request specifically includes:
monitoring an adding port mapping request sent by an application program through an Aidl interface or Intent, wherein the adding port mapping request at least comprises an internal port, an internal IP address and a protocol type;
judging whether the monitored data format and data type of the port adding mapping request conform to the predefined data format and data type;
if yes, adding the port adding mapping request into a linked list and marking the port adding mapping request as a port adding mapping request to be processed;
and reading the port adding mapping request to be processed in the linked list, and adding port mapping on the gateway equipment according to the port adding mapping request to be processed.
3. The UPNP traversal method according to claim 2, wherein the reading of the to-be-processed add-port mapping request in the linked list and the adding of the port mapping on the gateway device according to the to-be-processed add-port mapping request specifically includes:
acquiring the dialing type of the gateway equipment;
judging whether the UPnP service of the gateway equipment is normal or not;
if the UPnP service of the gateway equipment is normal, reading a mapping request of an adding port to be processed in the linked list;
adding port mapping on the gateway equipment according to the to-be-processed port mapping adding request and the dialing type of the gateway equipment;
and receiving prompt information which is returned by the gateway equipment and indicates whether the added port mapping is successful, and executing corresponding operation according to the prompt information.
4. The UPnP protocol-based NAT traversal method according to claim 3, wherein the adding of the port mapping on the gateway device according to the to-be-processed port mapping adding request and the dialing type of the gateway device specifically includes:
acquiring an added port mapping rule on the gateway equipment according to the to-be-processed port adding mapping request and the dialing type of the gateway equipment, and storing the added port mapping rule by using a hash array;
inquiring whether the same port mapping rule exists in the hash array or not according to the to-be-processed adding port mapping request, wherein the to-be-processed adding port mapping request at least comprises an internal port, an internal IP address and a protocol type;
if the same port mapping rule exists, acquiring an external port corresponding to the internal port in the port mapping rule so as to complete adding port mapping on the gateway equipment;
if the same port mapping rule does not exist, judging whether the to-be-processed adding port mapping request designates an external port or not;
if an external port is appointed, directly sending a request for adding port mapping to the gateway equipment, wherein the request comprises an internal IP address, an internal port, the external port, a protocol type and effective time, and enabling the gateway equipment to automatically add the port mapping according to the request;
if the external port is not appointed, setting the external port as the current maximum external port value in the hash array plus 1, and sending a request for adding port mapping to the gateway equipment, so that the gateway equipment automatically adds the port mapping according to the request.
5. The UPnP protocol-based NAT traversal method according to claim 3, wherein the receiving of the prompt information indicating whether the port addition mapping returned by the gateway device is successful or not, and the executing of the corresponding operation according to the prompt information specifically includes:
if prompt information of successful port adding mapping returned by the gateway equipment is received, marking a port adding mapping request to be processed in the linked list as being successfully added, and uploading the successfully added port mapping information to a P2P cloud server;
and if the prompt information of the addition port mapping failure returned by the gateway equipment is received, marking the to-be-processed addition port mapping request in the linked list as the addition failure.
6. A UPnP protocol-based NAT traversal system, comprising:
the gateway equipment searching module is used for searching gateway equipment supporting a UPNP protocol in a local area network where the terminal is located when the terminal starts the UPNP service;
the port mapping processing module is used for monitoring a port adding mapping request sent by an application program and adding port mapping on the gateway equipment according to the monitored port adding mapping request;
and the uploading module is used for uploading the successfully added port mapping information to the P2P cloud server, so that other network applications can acquire the port mapping information from the P2P cloud server to realize data communication with the application program.
7. The UPNP traversal system according to claim 6, wherein the port mapping processing module specifically includes:
the monitoring unit is used for monitoring an adding port mapping request sent by an application program through an Aidl interface or Intent, wherein the adding port mapping request at least comprises an internal port, an internal IP address and a protocol type;
the judging unit is used for judging whether the monitored data format and data type of the adding port mapping request conform to the predefined data format and data type;
the linked list processing unit is used for adding the port adding mapping request into the linked list and marking the port adding mapping request as a port adding mapping request to be processed if the port adding mapping request is consistent with the port adding mapping request;
and the port mapping processing unit is used for reading the port mapping request to be processed in the linked list and adding port mapping on the gateway equipment according to the port mapping request to be processed.
8. The UPnP protocol-based NAT traversal system according to claim 7, wherein the port mapping processing unit specifically includes:
a dialing type obtaining subunit, configured to obtain a dialing type of the gateway device;
a UPnP service judging subunit, configured to judge whether a UPnP service of the gateway device is normal;
a port mapping request reading subunit, configured to read, if the UPnP service of the gateway device is normal, a to-be-processed port mapping request to be added in the linked list;
a port mapping processing subunit, configured to add port mapping on the gateway device according to the to-be-processed port-added mapping request and the dialing type of the gateway device;
and the prompting subunit is used for receiving the prompting information which is returned by the gateway device and indicates whether the mapping of the added port is successful or not, and executing corresponding operation according to the prompting information.
9. The UPnP protocol-based NAT traversal system according to claim 8, wherein the port mapping processing subunit is specifically configured to:
acquiring an added port mapping rule on the gateway equipment according to the to-be-processed port adding mapping request and the dialing type of the gateway equipment, and storing the added port mapping rule by using a hash array;
inquiring whether the same port mapping rule exists in the hash array or not according to the to-be-processed adding port mapping request, wherein the to-be-processed adding port mapping request at least comprises an internal port, an internal IP address and a protocol type;
if the same port mapping rule exists, acquiring an external port corresponding to the internal port in the port mapping rule so as to complete adding port mapping on the gateway equipment;
if the same port mapping rule does not exist, judging whether the to-be-processed adding port mapping request designates an external port or not;
if an external port is appointed, directly sending a request for adding port mapping to the gateway equipment, wherein the request comprises an internal IP address, an internal port, the external port, a protocol type and effective time, and enabling the gateway equipment to automatically add the port mapping according to the request;
if the external port is not appointed, setting the external port as the current maximum external port value in the hash array plus 1, and sending a request for adding port mapping to the gateway equipment, so that the gateway equipment automatically adds the port mapping according to the request.
10. The UPnP protocol-based NAT traversal system according to claim 8, wherein the prompting subunit is specifically configured to:
if prompt information of successful port adding mapping returned by the gateway equipment is received, marking a port adding mapping request to be processed in the linked list as being successfully added, and controlling the uploading module to upload the successfully added port mapping information to the P2P cloud server;
and if the prompt information of the addition port mapping failure returned by the gateway equipment is received, marking the to-be-processed addition port mapping request in the linked list as the addition failure.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610278924.7A CN105979022B (en) | 2016-04-28 | 2016-04-28 | NAT (network Address translation) penetrating method and system based on UPnP (Universal plug and Play) protocol |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610278924.7A CN105979022B (en) | 2016-04-28 | 2016-04-28 | NAT (network Address translation) penetrating method and system based on UPnP (Universal plug and Play) protocol |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105979022A CN105979022A (en) | 2016-09-28 |
CN105979022B true CN105979022B (en) | 2020-10-02 |
Family
ID=56994544
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610278924.7A Active CN105979022B (en) | 2016-04-28 | 2016-04-28 | NAT (network Address translation) penetrating method and system based on UPnP (Universal plug and Play) protocol |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105979022B (en) |
Families Citing this family (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106507028A (en) * | 2016-11-29 | 2017-03-15 | 四川长虹电器股份有限公司 | A kind of Intranet in television video call penetrates direct-connected method |
CN108737581A (en) * | 2017-04-14 | 2018-11-02 | 中兴通讯股份有限公司 | A kind of gateway device, management method, apparatus and system |
CN110943937B (en) * | 2018-09-21 | 2023-04-11 | 金山云(深圳)边缘计算科技有限公司 | Local area network equipment utilization method and device |
CN111917449A (en) * | 2019-05-08 | 2020-11-10 | 丰鸟航空科技有限公司 | Outfield unmanned aerial vehicle system and data transmission method |
CN111800341B (en) * | 2020-07-03 | 2022-05-31 | 珠海金山网络游戏科技有限公司 | Cross-router terminal communication method and device |
CN112491591B (en) * | 2020-11-10 | 2023-05-30 | 杭州萤石软件有限公司 | Universal plug and play UPnP port mapping method and system |
CN112437168B (en) * | 2020-11-13 | 2023-09-01 | 广州朗国电子科技股份有限公司 | Intranet penetration system |
CN112671888A (en) * | 2020-12-21 | 2021-04-16 | 龙存(苏州)科技有限公司 | Remote connection method and system based on cloud service |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2009124450A1 (en) * | 2008-04-11 | 2009-10-15 | 中国科学院声学研究所 | Nat traversal method based on combination of technique of upnp and stun |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1909560A (en) * | 2005-08-03 | 2007-02-07 | 乐金电子(昆山)电脑有限公司 | Device and method for setting network address |
CN101702718A (en) * | 2009-11-18 | 2010-05-05 | 中兴通讯股份有限公司 | Method and device for managing user terminal equipment |
CN104104926B (en) * | 2014-07-30 | 2017-04-19 | 浙江宇视科技有限公司 | Universal plug and play (UPnP) monitoring terminal access method and access device |
-
2016
- 2016-04-28 CN CN201610278924.7A patent/CN105979022B/en active Active
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2009124450A1 (en) * | 2008-04-11 | 2009-10-15 | 中国科学院声学研究所 | Nat traversal method based on combination of technique of upnp and stun |
Also Published As
Publication number | Publication date |
---|---|
CN105979022A (en) | 2016-09-28 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105979022B (en) | NAT (network Address translation) penetrating method and system based on UPnP (Universal plug and Play) protocol | |
JP4327852B2 (en) | COMMUNICATION DEVICE, COMMUNICATION SETTING METHOD, COMMUNICATION SETTING PROGRAM, AND RECORDING MEDIUM CONTAINING COMMUNICATION SETTING PROGRAM | |
JP4417417B2 (en) | How to establish a peer-to-peer connection | |
US10498864B1 (en) | System and method for selecting connection mode between a client and a server | |
US7675914B2 (en) | Relay information setting method and device | |
EP3462713B1 (en) | Nat entry management method and apparatus, and nat device | |
JP7531697B2 (en) | Data processing method, device, related equipment and storage medium | |
US7839807B2 (en) | Communication apparatus, method executed by communication apparatus, and storage medium storing software for executing method | |
WO2008044432A1 (en) | Information communication device, information communication method and program | |
US20140359163A1 (en) | Methods and Systems for Enabling NAT Traversal | |
JP2016063425A (en) | Communication device, communication system, and communication method | |
US10462265B2 (en) | On-demand startup of offline servers and connection routing | |
WO2016078291A1 (en) | Method, apparatus and system for accessing file sharing server | |
JP2009230256A (en) | Communication controller, communication control method and communication control program | |
CN107872309B (en) | Self-adaptive method, device and equipment for network transmission medium and rate | |
US10805260B2 (en) | Method for transmitting at least one IP data packet, related system and computer program product | |
JP2017010388A (en) | Http server and control method for the same, image forming apparatus, and program | |
US9755928B2 (en) | Method, server and apparatus for establishing point-to-point connection | |
CN114844697B (en) | Method and device for realizing remote access of Windows computer to AD domain and readable storage medium | |
JP2013126219A (en) | Transfer server and transfer program | |
JP2015201758A (en) | Repeater, communication system, information processing method, and program | |
US20140351453A1 (en) | Node in a Network | |
US20140379785A1 (en) | Server Communication | |
CN113067908B (en) | NAT (network Address translation) traversing method and device, electronic equipment and storage medium | |
EP3588996A1 (en) | A method and a system for discovering compatible devices in a local network |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
TA01 | Transfer of patent application right | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20171201 Address after: 518000 Guangdong city of Shenzhen province Nanshan District Xili liuxiandong Zhongshan Road No. 1001 TCL Science Park Research Building D4 Building 8 layer B1 unit 802-1. Applicant after: SHENZHEN TCL HIGH-TECH DEVELOPMENT CO., LTD. Address before: 516006 Guangdong province Huizhou Zhongkai hi tech Development Zone No. nineteen District Applicant before: TCL Group Co., Ltd. |
|
GR01 | Patent grant | ||
GR01 | Patent grant |