CN105187568A - IPV4 address conversion method and device - Google Patents
IPV4 address conversion method and device Download PDFInfo
- Publication number
- CN105187568A CN105187568A CN201510494185.0A CN201510494185A CN105187568A CN 105187568 A CN105187568 A CN 105187568A CN 201510494185 A CN201510494185 A CN 201510494185A CN 105187568 A CN105187568 A CN 105187568A
- Authority
- CN
- China
- Prior art keywords
- character string
- numeral
- ipv4 address
- byte
- address
- 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.)
- Granted
Links
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/45—Network directories; Name-to-address mapping
- H04L61/4505—Network directories; Name-to-address mapping using standardised directories; using standardised directory access protocols
- H04L61/4511—Network directories; Name-to-address mapping using standardised directories; using standardised directory access protocols using domain name system [DNS]
-
- 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
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The invention discloses an IPV4 address conversion method and device. The method comprises the following steps of initializing a string array corresponding to a number of the IPV4 address; orderly extracting a number corresponding to one byte from the four bytes of the IPV4 address, acquiring corresponding character string, filling the character string to a position in a conversion result corresponding to the byte until the conversion of the four bytes of the IPV4 address is completed, and forming the converted address character string. By adopting the technical scheme of the invention, the problem in the current program design that the efficiency is low when an IP (Internet Protocol) address and the character string are exchanged through an API (Application Program Interface) can be overcome, the calculation is simple and the conversion efficiency of the IP address is greatly improved.
Description
Technical field
The present invention relates to computer systems technology field, particularly relate to a kind of IPV4 address conversion method and device.
Background technology
Botnet has that attack method is simple, impact is comparatively large, be difficult to features such as tracing, makes distributed denial of service attack (DDoS, DistributedDenialofService) obtain growing fast and day by day spreading unchecked.The Botnet of thousands of main frame composition is that ddos attack provides required bandwidth sum main frame, defines huge attack and network traffics, causes great harm to by attacking network.Improving constantly and developing along with ddos attack technology, ISP (ISP, InternetServiceProvider), ICP (ICP, InternetContentProvider), IDC (Internet data center, etc. InternetDataCenter) safety that faces of operator and operation challenge are also on the increase, operator must before DDoS threat affects key business and application, detection carried out to flow and is cleaned, guaranteeing the operation of network normal table and normally carrying out of business.
IP statistics is one of core technology of detecting of DDos with analyzing, IPV4 address is one group of character string be made up of four numerals, and it can convert the integer of a nybble to when transmission over networks, conveniently analyze, often need the IP address transition inside the message intercepted from network to become character string.
API (the application programming interface that current programming generally uses system to provide, ApplicationProgrammingInterface) exchange between IP address and character string is realized, the API that system provides is generally more common, but efficiency is lower, under the environment of two-forty message and large discharge, use the overall performance that these system interfaces can drag program beyond doubt greatly low.
Summary of the invention
In view of this, the embodiment of the present invention provides a kind of IPV4 address conversion method and device, to solve technical problem of the prior art.
First aspect, embodiments provides a kind of IPV4 address conversion method, comprising:
The character string dimension that initialization is corresponding with the numeral of IPV4 address;
From the nybble of IPV4 address, extract numeral corresponding to a byte successively, and obtain corresponding character string, be filled to position corresponding with this byte in transformation result, until complete the conversion of IPV4 address nybble, form the address character string after conversion.
Second aspect, the embodiment of the present invention additionally provides a kind of IPV4 address converting device, comprising:
Initialization module, for the character string dimension that initialization is corresponding with the numeral of IPV4 address;
Modular converter, for extracting numeral corresponding to a byte successively from the nybble of IPV4 address, and obtaining corresponding character string, being filled to position corresponding with this byte in transformation result, until complete the conversion of IPV4 address nybble, form the address character string after conversion.
A kind of IPV4 address conversion method that the embodiment of the present invention provides, the character string dimension overall by initialization one is corresponding with the numeral in IPV4 address byte, and set up the mapping relations of numeral and character string, the content of numeral correspondence from character string dimension corresponding to each byte of IPV4 directly copies to transformation result, eliminates memory copying; In addition, because the numeral forming IP address in IPV4 is 0 ~ 255, so a small amount of character string initialization can be used to add the method for static assignment, each conversion only needs to carry out 4 to 8 assign operations, operate short and sweet and assignment number of times is few, it is simple to calculate, improve the speed that IP address transition becomes character string widely.
Accompanying drawing explanation
By reading the detailed description done non-limiting example done with reference to the following drawings, other features, objects and advantages of the present invention will become more obvious:
Fig. 1 is a kind of IPV4 address conversion method flow chart that the embodiment of the present invention one provides;
Fig. 2 is the detailed process flow chart of a kind of IPV4 address conversion method described in Fig. 1;
Fig. 3 is a kind of IPV4 address conversion method flow chart that the embodiment of the present invention two provides;
Fig. 4 is a kind of IPV4 address converting device structured flowchart that the embodiment of the present invention three provides;
Fig. 5 is the concrete structure block diagram of a kind of IPV4 address converting device described in Fig. 4.
Embodiment
Below in conjunction with drawings and Examples, the present invention is described in further detail.Be understandable that, specific embodiment described herein is only for explaining the present invention, but not limitation of the invention.It also should be noted that, for convenience of description, illustrate only part related to the present invention in accompanying drawing but not full content.
Embodiment one
Fig. 1 is a kind of IPV4 address conversion method flow chart in the embodiment of the present invention one, present embodiments provide a kind of IPV4 address conversion method, the method can be performed by the device performing arbitrarily IPV4 address transition, and this device can pass through software/or hardware implementing.As shown in Figure 1, the method comprises:
The character string dimension that S110, initialization are corresponding with the numeral of IPV4 address;
In IPV4, regulation IP address size is 32, namely has 2^32-1=255 address, so the overall length of initialization here is 255 character string dimension str, corresponding with the numeral of IPV4 address.By the numeral of 0 to 255, arrange corresponding character string respectively, and the described character string arranged is formed character string dimension, and set up mapping relations that are digital and character string, mapping relations are as follows:
str[0]=”0”,str[1]=”1”,……str[10]=”10”,str[100]=”100”,……str[255]=”255”。
So analogize, so overall array only needs initialization once, just Initialize installation can be carried out in all addresses in IPV4, just can use in a program always.
S120, the numeral that an extraction byte is corresponding from the nybble of IPV4 address successively, and obtain corresponding character string, be filled to position corresponding with this byte in transformation result, until complete the conversion of IPV4 address nybble, form the address character string after conversion.
See Fig. 2, preferably, based on such scheme, this operation comprises:
S121, for IPV4 address to be converted, arrange IPV4 address described in pointed first character joint, as current byte;
Preferably, because IPV4 address comprises 4 bytes altogether, the first character of the joint of first character from left to right as IPV4 address described in described pointed is saved, the like, using the 4th byte from left to right as the end of described IPV4 address.
S122, use the numeral of described pointer extracting current byte;
S123, according to numeral and the mapping relations of character string, from initialization string array, inquiry obtains character string corresponding to described numeral;
S124, the character string inquired is filled to position corresponding with this byte in transformation result;
Preferably, because IPV4 address comprises 4 bytes altogether, described byte arranges 4 positions corresponded in transformation result, such as: first character joint correspondence position one, second byte correspondence position the two, three byte correspondence position the three, four byte correspondence position four.
S125, moving hand, judge whether the end reaching described IPV4 address, if, then end mark is set at the end of described transformation result, calculated address character string, if not, then using next byte as current byte, return the operation of the numeral performing described extraction current byte.
Preferably, if current byte is nybble, then end mark 0 is set at the end of described transformation result ret, calculated address character string also turns back in described transformation result ret, otherwise described transformation result ret current location is set to '. ', and return the operation of the numeral performing described extraction current byte.
The IPV4 address conversion method that the embodiment of the present invention one provides, the character string dimension overall by initialization one is corresponding with the numeral in IPV4 address byte, and set up the mapping relations of numeral and character string, so overall array only needs initialization once, just Initialize installation can be carried out in all addresses in IPV4, just can use in a program always; In addition, during conversion IP address, use pointer algorithm, pointer P is made to point to this IP, use pointer P can extract each byte successively from the IPV4 integer of nybble composition, pointer so just can be used to transmit address instead of real data, can transmission speed be improved, have and can save a large amount of internal memory.
Embodiment two
Fig. 3 is a kind of IPV4 address conversion method flow chart in the embodiment of the present invention two, and the technical scheme of the present embodiment, based on above-described embodiment one, the basis of embodiment one is done further optimize.
Further, obtain corresponding character string described, before being filled to position corresponding with this byte in transformation result, according to the length of described numeral, determine the assignment type of corresponding character string.This flow process specifically comprises:
If the described numeral of S310 is more than or equal to 100, then the character string of correspondence is split as a character type and a short carries out assignment;
If the described numeral of S320 is less than 100 and is more than or equal to 10, be then short by the character string assignment of correspondence;
If the described numeral of S330 is less than 10, be then character type by the character string assignment of correspondence.
Exemplary, a character type length is 1 byte, and a short length is 2 bytes.
Such as: if the numeral that current pointer points to byte corresponding is 192,192>100, according to the mapping relations of numeral with character string, the character string " 192 " of digital 192 correspondences is split into a character type " 1 " and a short " 92 " carries out assignment, then described transformation result ret length adds 3;
If the numeral that current pointer points to byte corresponding is 71,100>71>10, according to the mapping relations of numeral with character string, be short by character string " 71 " assignment of digital 71 correspondences, then described transformation result ret length adds 2;
If it is 1,1<10 that current pointer points to numeral corresponding to byte, be then character type by character string " 1 " assignment of digital 1 correspondence, then described transformation result ret length adds 1.
The IPV4 address conversion method that the embodiment of the present invention two provides, according to the length of described numeral, determine the assignment type of corresponding character string, each numeral carries out at most twice assign operation just can obtain transformation result, assignment method is short and sweet and assignment number of times is few, it is simple to calculate, each conversion only needs to carry out 4 to 8 assign operations, greatly improves the speed that IPV4 address transition becomes character string.
Embodiment three
A kind of IPV4 address converting device structured flowchart that Fig. 4 provides for the embodiment of the present invention three.The technical scheme of the present embodiment is based on above-described embodiment, and as shown in Figure 4, described IPV4 address converting device comprises:
Initialization module 410, for the character string dimension that initialization is corresponding with the numeral of IPV4 address;
Modular converter 420, for extracting numeral corresponding to a byte successively from the nybble of IPV4 address, and obtaining corresponding character string, being filled to position corresponding with this byte in transformation result, until complete the conversion of IPV4 address nybble, form the address character string after conversion.
On the basis of above-described embodiment, initialization module specifically may be used for: by the numeral of 0 to 255, arranges corresponding character string respectively, and the described character string arranged is formed character string dimension, and sets up mapping relations that are digital and character string.
On the basis of above-described embodiment, modular converter comprises:
Pointer unit 421, for for IPV4 address to be converted, arranges the first character joint of IPV4 address described in pointed, as current byte;
Extraction unit 422, for using the numeral of described pointer extracting current byte;
Query unit 423, obtains character string corresponding to described numeral for inquiry from initialization string array;
Filler cells 424, for being filled to position corresponding with this byte in transformation result by the character string inquired;
Judging unit 425, for moving hand, judges whether the end reaching described IPV4 address, if so, then end mark is set at the end of described transformation result, calculated address character string, if not, then using next byte as current byte, return the operation of the numeral performing described extraction current byte.
Further, this device also comprises assignment module, for obtaining corresponding character string, before being filled to position corresponding with this byte in transformation result, according to the length of described numeral, determines the assignment type of corresponding character string.
On the basis of above-described embodiment, assignment module specifically for:
If described numeral is more than or equal to 100, then the character string of correspondence is split as a character type and a short carries out assignment;
If described numeral is less than 100 and is more than or equal to 10, be then short shaping by the character string assignment of correspondence;
If described numeral is less than 10, be then character type by the character string assignment of correspondence.
The IPV4 address conversion method that the IPV4 address converting device that the embodiment of the present invention provides provides for performing the embodiment of the present invention, possesses corresponding function and beneficial effect.
Note, above are only preferred embodiment of the present invention and institute's application technology principle.Skilled person in the art will appreciate that and the invention is not restricted to specific embodiment described here, various obvious change can be carried out for a person skilled in the art, readjust and substitute and can not protection scope of the present invention be departed from.Therefore, although be described in further detail invention has been by above embodiment, the present invention is not limited only to above embodiment, when not departing from the present invention's design, can also comprise other Equivalent embodiments more, and scope of the present invention is determined by appended right.
Claims (10)
1. an IPV4 address conversion method, is characterized in that, comprising:
The character string dimension that initialization is corresponding with the numeral of IPV4 address;
From the nybble of IPV4 address, extract numeral corresponding to a byte successively, and obtain corresponding character string, be filled to position corresponding with this byte in transformation result, until complete the conversion of IPV4 address nybble, form the address character string after conversion.
2. method according to claim 1, it is characterized in that, numeral corresponding to a byte is extracted successively from the nybble of IPV4 address, and obtain corresponding character string, be filled to position corresponding with this byte in transformation result, until complete the conversion of IPV4 address nybble, the address character string formed after conversion comprises:
For IPV4 address to be converted, the first character joint of IPV4 address described in pointed is set, as current byte;
Use the numeral of described pointer extracting current byte;
From initialization string array, inquiry obtains character string corresponding to described numeral;
The character string inquired is filled to position corresponding with this byte in transformation result;
Moving hand, judges whether the end reaching described IPV4 address, if, then end mark is set at the end of described transformation result, calculated address character string, if not, then using next byte as current byte, return the operation of the numeral performing described extraction current byte.
3. method according to claim 1, is characterized in that, the initialization character string dimension corresponding with the numeral of IPV4 address comprises:
By the numeral of 0 to 255, corresponding character string is set respectively, and the described character string arranged is formed character string dimension, and set up mapping relations that are digital and character string.
4. method according to claim 1, is characterized in that, obtains corresponding character string, before being filled to position corresponding with this byte in transformation result, also comprises:
According to the length of described numeral, determine the assignment type of corresponding character string.
5. method according to claim 4, is characterized in that, according to the length of described numeral, determines that the assignment type of corresponding character string comprises:
If described numeral is more than or equal to 100, then the character string of correspondence is split as a character type and a short carries out assignment;
If described numeral is less than 100 and is more than or equal to 10, be then short shaping by the character string assignment of correspondence;
If described numeral is less than 10, be then character type by the character string assignment of correspondence.
6. an IPV4 address converting device, is characterized in that, comprising:
Initialization module, for the character string dimension that initialization is corresponding with the numeral of IPV4 address;
Modular converter, for extracting numeral corresponding to a byte successively from the nybble of IPV4 address, and obtaining corresponding character string, being filled to position corresponding with this byte in transformation result, until complete the conversion of IPV4 address nybble, form the address character string after conversion.
7. device according to claim 6, is characterized in that, described modular converter comprises:
Pointer unit, for for IPV4 address to be converted, arranges the first character joint of IPV4 address described in pointed, as current byte;
Extraction unit, for using the numeral of described pointer extracting current byte;
Query unit, obtains character string corresponding to described numeral for inquiry from initialization string array;
Filler cells, for being filled to position corresponding with this byte in transformation result by the character string inquired;
Judging unit, for moving hand, judges whether the end reaching described IPV4 address, if so, then end mark is set at the end of described transformation result, calculated address character string, if not, then using next byte as current byte, return the operation of the numeral performing described extraction current byte.
8. device according to claim 6, is characterized in that, described initialization module specifically for:
By the numeral of 0 to 255, corresponding character string is set respectively, and the described character string arranged is formed character string dimension, and set up mapping relations that are digital and character string.
9. device according to claim 6, is characterized in that, also comprises:
Assignment module, for obtaining corresponding character string, before being filled to position corresponding with this byte in transformation result, according to the length of described numeral, determines the assignment type of corresponding character string.
10. device according to claim 9, is characterized in that, described assignment module specifically for:
If described numeral is more than or equal to 100, then the character string of correspondence is split as a character type and a short carries out assignment;
If described numeral is less than 100 and is more than or equal to 10, be then short shaping by the character string assignment of correspondence;
If described numeral is less than 10, be then character type by the character string assignment of correspondence.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510494185.0A CN105187568B (en) | 2015-08-12 | 2015-08-12 | A kind of IPV4 address conversion methods and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510494185.0A CN105187568B (en) | 2015-08-12 | 2015-08-12 | A kind of IPV4 address conversion methods and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105187568A true CN105187568A (en) | 2015-12-23 |
CN105187568B CN105187568B (en) | 2018-09-25 |
Family
ID=54909407
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201510494185.0A Active CN105187568B (en) | 2015-08-12 | 2015-08-12 | A kind of IPV4 address conversion methods and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105187568B (en) |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1269657A (en) * | 2000-04-28 | 2000-10-11 | 西南交通大学 | Digital data converting method |
CN101557349A (en) * | 2009-05-26 | 2009-10-14 | 孙斌 | Method and system for processing Internet data message |
CN102332030A (en) * | 2011-10-17 | 2012-01-25 | 中国科学院计算技术研究所 | Data storing, managing and inquiring method and system for distributed key-value storage system |
US20120198091A1 (en) * | 2011-01-28 | 2012-08-02 | Hitachi, Ltd. | Network system, control apparatus and network apparatus |
CN103177000A (en) * | 2011-12-21 | 2013-06-26 | 卓望数码技术(深圳)有限公司 | Grouping method of Internet protocol (IP) addresses or cell phone numbers and query method of attribution place |
CN103297554A (en) * | 2012-03-02 | 2013-09-11 | 中兴通讯股份有限公司 | Method and device for compatibility processing of IPv4 and IPv6 |
-
2015
- 2015-08-12 CN CN201510494185.0A patent/CN105187568B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1269657A (en) * | 2000-04-28 | 2000-10-11 | 西南交通大学 | Digital data converting method |
CN101557349A (en) * | 2009-05-26 | 2009-10-14 | 孙斌 | Method and system for processing Internet data message |
US20120198091A1 (en) * | 2011-01-28 | 2012-08-02 | Hitachi, Ltd. | Network system, control apparatus and network apparatus |
CN102332030A (en) * | 2011-10-17 | 2012-01-25 | 中国科学院计算技术研究所 | Data storing, managing and inquiring method and system for distributed key-value storage system |
CN103177000A (en) * | 2011-12-21 | 2013-06-26 | 卓望数码技术(深圳)有限公司 | Grouping method of Internet protocol (IP) addresses or cell phone numbers and query method of attribution place |
CN103297554A (en) * | 2012-03-02 | 2013-09-11 | 中兴通讯股份有限公司 | Method and device for compatibility processing of IPv4 and IPv6 |
Non-Patent Citations (1)
Title |
---|
UNIMEN: "IP地址字符串与整数的互相转化转换", 《BLOG.CSDN.NET/UNIMEN/ARTICLE/DETAILS/6844456》 * |
Also Published As
Publication number | Publication date |
---|---|
CN105187568B (en) | 2018-09-25 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102025567A (en) | Sharing access detection method and related device | |
CN105681125A (en) | Method for counting traffic of virtual machine extranet of cloud platform | |
CN102904823B (en) | A kind of multiple services Accurate Data Flow Control method of multi-user based on memory | |
CN102594809A (en) | Method and system for rapidly scanning files | |
CN103414605A (en) | Desktop cloud monitoring method based on exchange gateway | |
CN111030999B (en) | Method for extracting files based on network data packet | |
CN103024089A (en) | Network address translation method and device | |
CN101986642B (en) | Detection system and method of Domain Flux data stream | |
CN102811158A (en) | Data positioning and recombining method and corresponding device | |
CN104506460B (en) | A kind of method for realizing the distribution of NAPT port resources | |
CN105337850A (en) | Internet of Things data processing method and internet of Things gateway | |
CN103281317B (en) | A kind of attack testing method of software defined network | |
CN105376338A (en) | Translation method between IPv4 and IPv6 and device | |
Garsva et al. | Packet size distribution tendencies in computer network flows | |
CN105187568A (en) | IPV4 address conversion method and device | |
CN108667782B (en) | DDoS attack defense method and system for DNS service | |
CN103001966A (en) | Processing and identifying method and device for private network IP | |
CN107547690A (en) | Port assignment method, apparatus, NAT device and storage medium in NAT | |
CN102316173A (en) | Method and device for aggregating network address | |
CN103595827A (en) | IP address identifying method and device for CDN (Content Distribution Network) source station | |
CN109981386B (en) | Network quality testing method, testing server and testing system | |
CN104683491B (en) | A kind of method and system for the Internet Protocol address for obtaining virtual machine | |
CN112995353B (en) | IPv6 address survivability scanning system and method based on flow analysis | |
CN107231339B (en) | Method and device for detecting DDoS attack | |
CN104836700A (en) | NAT (Network Address Translation) host number detection method based on IPID and probability statistics model |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
CB02 | Change of applicant information |
Address after: 705-708, room two, No. 121, north south of the Five Ridges Avenue, Chancheng District, Guangdong, Foshan, 528000 Applicant after: GUANGDONG RUIJIANG CLOUD COMPUTING CO., LTD. Address before: Chancheng District of Guangdong city of Foshan province south of the Five Ridges 528000 Avenue North 121 East International A District Office 7-8 Applicant before: Guangdong Efly Network Co., Ltd. |
|
COR | Change of bibliographic data | ||
GR01 | Patent grant | ||
GR01 | Patent grant |