Summary of the invention
In view of this, can be improved the penetrance of NAT device the purpose of the present invention is to provide a kind of NAT penetrating method;It is a further object of the present invention to provide a kind of NAT penetrating device, equipment and computer readable storage mediums, all have above-mentioned beneficialEffect.
In order to solve the above technical problems, the present invention provides a kind of NAT penetrating method, comprising:
When receiving NAT and penetrating instruction, the port type of NAT device is detected;
It is that NAT device setting is corresponding pre- according to the first preset rules if the port type is host portSurvey port numbers;Wherein, the host port characterizes when the NAT device accesses different outer net equipment using different mapped portsNumber, and there is mapped port number identical with host side slogan in the different mapped port number;
If the port type be fixed port, is searched from corresponding gateway server according to the second preset rules andThe corresponding prediction port numbers of the NAT device;Wherein, the fixed port characterizes the NAT device and accesses different outer net equipmentWhen use identical mapped port number;
If the port type is symmetrical ports, terminate process;Wherein, the symmetrical ports characterize the NAT deviceUsing different mapped ports number when accessing different outer net equipment, and it is not present and the master in the different mapped port numberThe identical mapped port number of generator terminal slogan;
Prediction port numbers corresponding with present port type are sent to the gateway server, so that target outer net equipment obtainsIt takes the corresponding prediction port numbers and so that the NAT device is realized that NAT is penetrated with the target outer net equipment by the packet that burrows.
Preferably, described when receiving NAT and penetrating instruction, the port type for detecting NAT device specifically includes:
When receiving the NAT and penetrating instruction, type detection packet is sent to the first gateway server;
Judge whether the host side slogan is identical as mapped port No. the first;
If they are the same, then the port type for determining the NAT device is the host port;
If it is different, the type detection packet is then sent to the second gateway server;
Judge whether mapped port No. the second is identical as the mapped port No. first;
If they are the same, then determine that the port type is the fixed port;
If it is different, then determining that the port type is the symmetrical ports.
It preferably, is that the NAT device is set according to the first preset rules if the port type is host portCorresponding prediction port numbers are set to specifically include:
If the port type be host port, judge it is upper one predict port numbers whether with the host side slogan phaseTogether;
If so, setting any in addition to the host side slogan for the current prediction port numbers of the NAT deviceMapped port number;
If it is not, then setting mapping identical with the host side slogan for the current prediction port numbers of the NAT devicePort numbers.
Preferably, the prediction port numbers are sent to the gateway server described, so as to the acquisition of target outer net equipmentPrediction port numbers and after making the NAT device and the target outer net equipment realize that NAT is penetrated by the packet that burrows, into oneStep includes:
Connection test bag is sent to the target outer net equipment.
Preferably, the type detection packet is specially UDP packet.
Preferably, after for the NAT device, the prediction port numbers are set, further comprise:
Record the corresponding relationship of the host side slogan and each prediction port numbers.
Preferably, after detecting that the port type is the symmetrical ports, further comprise:
Issue prompt information.
In order to solve the above technical problems, the present invention also provides a kind of NAT penetrating devices, comprising:
Detection module, for detecting the port type of NAT device when receiving NAT and penetrating instruction;
First setup module is the NAT according to the first preset rules if being host port for the port typeCorresponding prediction port numbers are arranged in equipment;Wherein, the host port characterizes when the NAT device accesses different outer net equipment and makesWith different mapped ports number, and there is mapped port number identical with host side slogan in the different mapped port number;
Second setup module, if being fixed port for the port type, according to the second preset rules from correspondingPrediction port numbers corresponding with the NAT device are searched in gateway server;Wherein, the fixed port characterizes the NAT and setsIdentical mapped port number is used when the different outer net equipment of standby access;
Third setup module terminates process if being symmetrical ports for the port type;Wherein, the symmetrical endOral thermometer is levied when the NAT device accesses different outer net equipment using different mapped ports number, and the different mapped portMapped port number identical with the host side slogan is not present in number;
Burrow module, for sending prediction port numbers corresponding with present port type to the gateway server, so as toTarget outer net equipment obtains the corresponding prediction port numbers and sets the NAT device with the target outer net by the packet that burrowsIt is standby to realize that NAT is penetrated.
In order to solve the above technical problems, the present invention also provides a kind of NAT to penetrate equipment, comprising:
Memory, for storing computer program;
Processor, the step of any of the above-described kind of NAT penetrating method is realized when for executing the computer program.
In order to solve the above technical problems, the present invention also provides a kind of computer readable storage medium, it is described computer-readableComputer program is stored on storage medium, the computer program realizes that any of the above-described kind of NAT is penetrated when being executed by processorThe step of method.
A kind of NAT penetrating method provided by the invention, compared to the prior art in, when the same NAT device access it is differentOuter net equipment, if the mapped port number of corresponding different outer net equipment is different, which can not achieve NATThe case where penetrating, this programme are when the same NAT device accesses different outer net equipment, if corresponding different outer net equipment is reflectedIt penetrates that port numbers are different, but exists in different mapped port number identical with the host side slogan of the NAT deviceMapped port number is then that corresponding prediction port numbers are arranged in the NAT device according to the first preset rules.As it can be seen that this programme increasesNAT device gets a possibility that prediction port numbers, so as to be able to carry out the probability penetrated higher for NAT device, therefore improvesThe penetrance of NAT device.
In order to solve the above technical problems, the present invention also provides a kind of NAT penetrating device, equipment and computer-readable storagesMedium all has above-mentioned beneficial effect.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, completeSite preparation description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based onEmbodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every otherEmbodiment shall fall within the protection scope of the present invention.
The core of the embodiment of the present invention is to provide a kind of NAT penetrating method, can be improved the penetrance of NAT device;This hairBright another core is to provide a kind of NAT penetrating device, equipment and computer readable storage medium, all has above-mentioned beneficial to effectFruit.
It is right with reference to the accompanying drawings and detailed description in order to make those skilled in the art more fully understand the present invention programThe present invention is described in further detail.
Fig. 1 is a kind of flow chart of NAT penetrating method provided in an embodiment of the present invention.As shown in Figure 1, a kind of NAT is penetratedMethod includes:
S10: when receiving NAT and penetrating instruction, the port type of NAT device is detected.
Specifically, NAT, which is penetrated, refers to that triggering NAT device carries out the operational order that NAT is penetrated, the present embodiment pairNAT penetrates the particular content of instruction without limitation.It is understood that NAT is penetrated namely network address translation or network addressTranslation, the essence that NAT is penetrated are the mapped ports number of predicting NAT equipment, and mapped port is arranged in the NAT device of different port typeNumber rule it is different.Therefore in the present embodiment, instruction is penetrated by receiving NAT, with the port class of detection trigger NAT deviceType.Specifically, specified operation content is executed generally by control NAT device, to detect the port class of NAT device itselfType, the present embodiment to detection NAT device port type concrete mode without limitation.
S20: being that corresponding prediction end is arranged in NAT device according to the first preset rules if port type is host portSlogan;Wherein, using different mapped ports number when host port characterization NAT device accesses different outer net equipment, and it is differentThere is mapped port number identical with host side slogan in mapped port number.
Specifically, if it is detected that the port type of NAT device is that host port namely NAT device access different outer nets and setUsing different mapped ports number when standby, and there is mapped port identical with host side slogan in different mapped ports numberNumber, then it is that corresponding default port numbers are arranged in NAT device according to the first preset rules.It should be noted that the first preset rulesIt can be and select any one mapped port number as current prediction port numbers from the set of mapped port number, be also possible toFrom the set of mapped port number, select any one mapped port number in addition to host side slogan as prediction port numbers,The present embodiment to the first preset rules without limitation.
S30: if port type be fixed port, is searched from corresponding gateway server according to the second preset rules andThe corresponding prediction port numbers of NAT device;Wherein, using identical when fixed port characterization NAT device accesses different outer net equipmentMapped port number.
Specifically, if it is detected that the port type of NAT device is that fixed port namely NAT device access different outer nets and setIdentical mapped port number is used when standby.It in the case, then can be corresponding with the NAT device according to the second preset rulesMapped port number corresponding with the NAT device is searched in gateway server.That is, being previously stored in gateway serverThe host side slogan of NAT device and each mapped port number then take from gateway when the port type of NAT device is fixed portPrediction port numbers of the corresponding mapped port number as the NAT device are searched in business device.
S40: if port type is symmetrical ports, terminate process;Wherein, the access of symmetrical ports characterization NAT device is differentUsing different mapped ports number when outer net equipment, and reflected in different mapped ports number there is no identical with host side sloganPenetrate port numbers.
Specifically, if it is detected that the port type of NAT device is that symmetrical ports namely NAT device access different outer nets and setUsing different mapped ports number when standby, and mapped port identical with host side slogan is not present in different mapped ports numberNumber, that is to say, that the mapped port number of NAT device and host side slogan are different, in this case, then can not obtainThe prediction port numbers of NAT device namely the NAT device not can be carried out NAT and penetrate operation, therefore, terminate process.
S50: prediction port numbers corresponding with present port type are sent to gateway server, so that target outer net equipment obtainsIt takes prediction port numbers and so that NAT device is realized that NAT is penetrated with target outer net equipment by the packet that burrows.
After for NAT device, prediction port numbers corresponding with present port type are set, namely in two different netsNAT device in network gets respective prediction port numbers respectively, and respective prediction port numbers are then sent to gateway respectivelyServer, and by gateway server transfer, informs the prediction port numbers of other side oneself, in order to two NAT device respectively toOther side sends the packet that burrows, to realize that NAT is penetrated.
It should be noted that the NAT device test statistics through 60,000 fiber optic networks, the NAT device of the prior art are wornSaturating rate is 30% or so, and NAT penetrating method provided by the present embodiment, and the penetrance of NAT device may make to reach 96%.
NAT penetrating method provided in this embodiment, comprising: when receiving NAT and penetrating instruction, detect the end of NAT deviceMouth type;It is that corresponding prediction port numbers are arranged in NAT device according to the first preset rules if port type is host port;Wherein, using different mapped ports number when host port characterization NAT device accesses different outer net equipment, and different mapping endsThere is mapped port number identical with host side slogan in slogan;If port type is fixed port, according to the second default rulePrediction port numbers corresponding with NAT device are then searched from corresponding gateway server;Wherein, fixed port characterizes NAT deviceIdentical mapped port number is used when accessing different outer net equipment;If port type is symmetrical ports, terminate process;Wherein,Using different mapped ports number when symmetrical ports characterization NAT device accesses different outer net equipment, and different mapped ports numberIn be not present mapped port number identical with host side slogan;Prediction port numbers are sent to gateway server, are then taken to gatewayBusiness device sends port numbers corresponding with present port type, so that target outer net equipment obtains corresponding prediction port numbers and passes throughThe packet that burrows makes NAT device realize that NAT is penetrated with target outer net equipment.
In compared to the prior art, when the same NAT device accesses different outer net equipment, if corresponding different outer net is setWhen standby mapped port number is different, then the NAT device can not achieve the case where NAT is penetrated, and this programme is as the same NATEquipment accesses different outer net equipment, if the mapped port number of corresponding different outer net equipment is different, but it is differentMapped port number in exist mapped port number identical with the host side slogan of the NAT device, then according to the first preset rulesFor the NAT device, corresponding prediction port numbers are set.As it can be seen that this programme increase NAT device get prediction port numbers canEnergy property, so that NAT device is able to carry out, the probability penetrated is higher, therefore improves the penetrance of NAT device.
Fig. 2 is that S10 detects NAT device when receiving NAT and penetrating instruction in a kind of NAT penetrating method shown in FIG. 1The specific flow chart of port type.Referring to FIG. 2, the process specifically includes:
S101: when receiving NAT and penetrating instruction, type detection packet is sent to the first gateway server;
S102: judge whether host side slogan is identical as mapped port No. the first;
S103: if they are the same, then determine the port type of NAT device for host port;
S104: if it is different, type detection packet is then sent to the second gateway server;
S105: judge whether mapped port No. the second is identical as mapped port No. the first;
S106: if they are the same, then determine port type for fixed port;
S107: if it is different, then determining port type for symmetrical ports.
Specifically, type detection packet is sent to the first gateway server first when receiving NAT and penetrating instruction, withMapped port No. the first is obtained, and judges whether host side slogan is identical as mapped port No. the first, if they are the same, then it represents that shouldNAT device is host port;If it is different, then needing further to judge that the host port is fixed port or symmetrical ports, specificallyMethod are as follows: type detection packet is sent to the second gateway server, and judge mapped port No. the second whether with first mapping endSlogan is identical, namely when judging to send the second gateway server for type detection packet, whether the mapped port number of NAT device is sent outIt is raw to change, if no change has taken place, then it represents that the NAT device accesses used mapped port phase when different outer net equipmentTogether, then determine the NAT device for fixed port;If changing, then it represents that the NAT device accesses different outer net equipment when institutesThe mapped port number used is different, then determines the NAT device for symmetrical ports.
It is understood that gateway server refers to realizing the server of network interconnection, therefore type detection packet is dividedIt is not sent to the first gateway server and the second gateway server namely indicates type detection packet being sent to different outer net equipment,To obtain corresponding mapped port number namely mapped port No. the first and mapped port No. the second respectively.
As preferred embodiment, in the present embodiment, type detection packet is specially UDP packet.Since UDP packet is not belonging toConnecting-type agreement, thus have resource consumption small, the fast advantage of processing speed, even and if even during using UDP packetYou lose one or two of data packet, will not have much impact to reception result, so using UDP packet as class in the present embodimentType detection packet.
As it can be seen that in the present embodiment, by the way that type detection packet is respectively sent to the first gateway server and the second gatewayThe mode of server determines the port type of NAT device, and judgment mode is simple, and judging result is accurate.
On the basis of the above embodiments, the present embodiment has made further instruction and optimization to technical solution, specifically,It is that the corresponding prediction port numbers of NAT device setting specifically include according to the first preset rules if port type is host port:
If port type is host port, judge whether upper prediction port numbers are identical as host side slogan;
If so, setting any mapped port in addition to host side slogan for the current prediction port numbers of NAT deviceNumber;
If it is not, then setting mapped port number identical with host side slogan for the current prediction port numbers of NAT device.
Specifically, in the present embodiment, when the port type for judging NAT device is host port, then further sentencingWhether disconnected upper prediction port numbers are identical as host side slogan;Namely judge currently mapped port number identical with host side sloganIt is whether occupied, if so, any being reflected what the current prediction port numbers of NAT device were set as in addition to host side sloganPenetrate port numbers;If it is not, then setting mapped port number identical with host side slogan for the current prediction port numbers of NAT device.Namely in the case that identical with host side slogan mapped port number is unoccupied, preferentially the prediction port numbers of NAT device are setIt is set to mapped port number identical with the host side slogan of NAT device;If mapped port number identical with host side slogan isIt is occupied, then set the prediction port numbers of NAT device to any mapped port number in addition to host side slogan.
For example, it is assumed that current host side slogan is 4000, the prediction port numbers when accessing outer net equipment A are 4000,Then when accessing another outer net equipment B, other port numbers in addition to 4000 are set by prediction port numbers, such as 5000.Due toIt predicts that port numbers are from 1 to 65535 totally 65535 port numbers, therefore in random selection, uses identical prediction endThe probability of slogan is very little, therefore can be realized NAT and penetrate.
As preferred embodiment, prediction port numbers are being sent to gateway server, so as to the acquisition of target outer net equipmentAfter predicting port numbers and so that NAT device and target outer net equipment is realized that NAT is penetrated by the packet that burrows, further comprise:
Connection test bag is sent to target outer net equipment.
That is, after NAT device burrows packet to the transmission of target outer net equipment, in order to ensure the reliable of data transmissionProperty, before transmission services data packet, further detected by way of sending connection test bag to target outer net equipment currentPenetrate whether process succeeds.It should be noted that since the transmission process of business data packet is two-way, general connectionNAT device sends respectively to other side with target outer net equipment and is connected to test bag.
As it can be seen that in the present embodiment, by sending connection test bag to target outer net equipment, further ensureing and passing through this realityThe mode for applying example carries out the reliability that NAT is penetrated.
Further comprise after for NAT device, prediction port numbers are set as preferred embodiment:
Record the corresponding relationship of host side slogan and each prediction port numbers.
That is, by host side slogan and being NAT device setting after prediction port numbers are arranged for NAT deviceEach prediction mapped port number is recorded.It should be noted that the mode of record can be by way of log is written, it can alsoTo be by the record storage to database, the present embodiment is not limited this.But it is the need to ensure that host side slogan and sets every timeThe prediction port numbers set are correspondingly arranged, in order to the subsequent corresponding relationship checked host side slogan and predict port numbers.
In the present embodiment, the information that can also further record corresponding outer net equipment, is equally checked convenient for the later period, whenSo, other information can also be recorded according to actual needs, and the present embodiment does not limit this.
Further comprise after detecting that port type is symmetrical ports as preferred embodiment:
Issue prompt information.
It is penetrated since symmetrical ports cannot achieve, it, can when the port type for detecting NAT device is symmetrical portsThe case where current NAT device of operator is prompted in a manner of by issuing prompt information, so that operator knows that the NAT is set in timeStandby cannot achieve penetrates.
It is understood that the mode for issuing prompt information is varied, can be by showing corresponding text or figureAs the mode of information is prompted, it is also possible to be prompted by way of suggestion device such as buzzer or indicator light, this realityApply example to issue prompt information concrete mode and prompt information particular content without limitation, as long as can be to detectionExit port type is that symmetrical ports are prompted, and is the protection scheme of the present embodiment.
A kind of embodiment of NAT penetrating method provided by the invention is described in detail above, the present invention is alsoProvide a kind of NAT penetrating device corresponding with this method, equipment and computer readable storage medium, due to device, equipment andThe embodiment of computer readable storage medium part and the embodiment of method part mutually correlate, therefore device, equipment and calculatingThe embodiment of machine readable storage medium storing program for executing part refers to the description of the embodiment of method part, wouldn't repeat here.
Fig. 3 is a kind of structure chart of NAT penetrating device provided in an embodiment of the present invention, as shown in figure 3, a kind of NAT is penetratedDevice includes:
Detection module 31, for detecting the port type of NAT device when receiving NAT and penetrating instruction;
First setup module 32 is set if being host port for port type according to the first preset rules for NAT deviceSet corresponding prediction port numbers;Wherein, using different mapping ends when host port characterization NAT device accesses different outer net equipmentSlogan, and there is mapped port number identical with host side slogan in different mapped ports number;
Second setup module 33, if being fixed port for port type, according to the second preset rules from corresponding netIt closes and searches prediction port numbers corresponding with NAT device in server;Wherein, fixed port characterization NAT device accesses different outer netsIdentical mapped port number is used when equipment;
Third setup module 34 terminates process if being symmetrical ports for port type;Wherein, symmetrical ports characterizeUsing different mapped ports number when NAT device accesses different outer net equipment, and it is not present and master in different mapped ports numberThe identical mapped port number of generator terminal slogan;
The module that burrows 35, for sending prediction port numbers corresponding with present port type to gateway server, so as to meshMark outer net equipment obtains corresponding prediction port numbers and so that NAT device is realized that NAT is penetrated with target outer net equipment by the packet that burrows.
NAT penetrating device provided in an embodiment of the present invention, the beneficial effect with above-mentioned NAT penetrating method.
Fig. 4 is the structure chart that a kind of NAT provided in an embodiment of the present invention penetrates equipment, as shown in figure 4, a kind of NAT is penetratedEquipment includes:
Memory 41, for storing computer program;
Processor 42 is realized when for executing computer program such as the step of above-mentioned NAT penetrating method.
NAT provided in an embodiment of the present invention penetrates equipment, the beneficial effect with above-mentioned NAT penetrating method.
In order to solve the above technical problems, the present invention also provides a kind of computer readable storage medium, computer-readable storageIt is stored with computer program on medium, realizes when computer program is executed by processor such as the step of above-mentioned NAT penetrating method.
Computer readable storage medium provided in an embodiment of the present invention, the beneficial effect with above-mentioned NAT penetrating method.
NAT penetrating method, device, equipment and computer readable storage medium provided by the present invention have been carried out in detail aboveIt is thin to introduce.Principle and implementation of the present invention are described for specific embodiment used herein, above embodimentsIllustrate to be merely used to help understand method and its core concept of the invention.It should be pointed out that for the common skill of the art, without departing from the principle of the present invention, can be with several improvements and modifications are made to the present invention for art personnel, these changeIt is also fallen within the protection scope of the claims of the present invention into modification.
Each embodiment is described in a progressive manner in specification, the highlights of each of the examples are with other realitiesThe difference of example is applied, the same or similar parts in each embodiment may refer to each other.For device disclosed in embodimentSpeech, since it is corresponded to the methods disclosed in the examples, so being described relatively simple, related place is referring to method part illustration?.
Professional further appreciates that, unit described in conjunction with the examples disclosed in the embodiments of the present disclosureAnd algorithm steps, can be realized with electronic hardware, computer software, or a combination of the two, in order to clearly demonstrate hardware andThe interchangeability of software generally describes each exemplary composition and step according to function in the above description.TheseFunction is implemented in hardware or software actually, the specific application and design constraint depending on technical solution.ProfessionTechnical staff can use different methods to achieve the described function each specific application, but this realization is not answeredThink beyond the scope of this invention.