CN105187568B - A kind of IPV4 address conversion methods and device - Google Patents

A kind of IPV4 address conversion methods and device Download PDF

Info

Publication number
CN105187568B
CN105187568B CN201510494185.0A CN201510494185A CN105187568B CN 105187568 B CN105187568 B CN 105187568B CN 201510494185 A CN201510494185 A CN 201510494185A CN 105187568 B CN105187568 B CN 105187568B
Authority
CN
China
Prior art keywords
character string
byte
ipv4
address
addresses
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
Application number
CN201510494185.0A
Other languages
Chinese (zh)
Other versions
CN105187568A (en
Inventor
梁润强
史伟
黄劲聪
曾宪力
关志来
麦剑
刘杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Ruijiang Cloud Computing Co Ltd
Original Assignee
Guangdong Ruijiang Cloud Computing Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Guangdong Ruijiang Cloud Computing Co Ltd filed Critical Guangdong Ruijiang Cloud Computing Co Ltd
Priority to CN201510494185.0A priority Critical patent/CN105187568B/en
Publication of CN105187568A publication Critical patent/CN105187568A/en
Application granted granted Critical
Publication of CN105187568B publication Critical patent/CN105187568B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/45Network directories; Name-to-address mapping
    • H04L61/4505Network directories; Name-to-address mapping using standardised directories; using standardised directory access protocols
    • H04L61/4511Network directories; Name-to-address mapping using standardised directories; using standardised directory access protocols using domain name system [DNS]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses

Abstract

The invention discloses a kind of IPV4 address conversion methods and device, this method to include:Initialize character string dimension corresponding with the number of the addresses IPV4;The corresponding number of a byte is extracted from the nybble of the addresses IPV4 successively, and obtains corresponding character string, filling to position corresponding with the byte in transformation result forms transformed address character string until completing the conversion of the addresses IPV4 nybble.Using the technical program, overcomes in present procedure design and the problem of existing inefficiency, calculate simply when realizing the exchange between IP address and character string by API, greatly improve the transfer efficiency of IP address.

Description

A kind of IPV4 address conversion methods and device
Technical field
The present invention relates to computer systems technology field more particularly to a kind of IPV4 address conversion methods and device.
Background technology
Botnet has the characteristics that attack method is simple, is affected, is difficult to trace so that distributed denial of service is attacked (DDoS, Distributed Denial of Service) is hit to obtain quickly growing and increasingly spreading unchecked.Thousands of host compositions Botnet provide required bandwidth and host for ddos attack, form huge attack and network flow, it is right Great harm is caused by attacking network.With the continuous improvement and development of ddos attack technology, (Internet service carries ISP For quotient, Internet Service Provider), ICP (internet content provider, Internet Content Provider the safety and operation that), the operators such as IDC (Internet data center, Internet Data Center) face are chosen War is also on the increase, and operator must be detected flow and be subject to before DDoS threatens influence key business and application Cleaning, it is ensured that the operation of network normal table and the normal development of business.
It is one of the core technology of DDos detections that IP, which is counted with analysis, and the addresses IPV4 are one group of word being made of four numbers Symbol string, and it can be converted into the integer of a nybble in transmission over networks, analyze for convenience, it is often necessary to it will be from network On IP address conversion inside the message that intercepts at character string.
Current programming generally uses API (application programming interface, the Application that system provides Programming Interface) realize the exchange between IP address and character string, the API that system provides is generally relatively more logical With, but under efficiency is relatively low, in the environment of high-speed message and big flow, being undoubtedly using these system interfaces can be significantly The overall performance for having dragged program low.
Invention content
In view of this, a kind of IPV4 address conversion methods of offer of the embodiment of the present invention and device, to solve in the prior art The technical issues of.
In a first aspect, an embodiment of the present invention provides a kind of IPV4 address conversion methods, including:
Initialize character string dimension corresponding with the number of the addresses IPV4;
The corresponding number of a byte is extracted from the nybble of the addresses IPV4 successively, and obtains corresponding character string, is filled out It is charged in transformation result position corresponding with the byte, until completing the conversion of the addresses IPV4 nybble, is formed transformedly Location character string.
Second aspect, the embodiment of the present invention additionally provide a kind of IPV4 address converting devices, including:
Initialization module, for initializing character string dimension corresponding with the number of the addresses IPV4;
Conversion module, for extracting the corresponding number of a byte, and acquisition pair from the nybble of the addresses IPV4 successively The character string answered, filling to position corresponding with the byte in transformation result, until completing the conversion of the addresses IPV4 nybble, shape At transformed address character string.
A kind of IPV4 address conversion methods provided in an embodiment of the present invention, by initializing a global character string dimension It is corresponding with the number in IPV4 address bytes, and the mapping relations of number and character string are established, according to each byte institutes of IPV4 Corresponding content is copied directly to transformation result by corresponding number from character string dimension, eliminates memory copying;In addition, by The number that IP address is formed in IPV4 is 0~255, it is possible to use the initialization of a small amount of character string plus the side of static assignment Method, every time conversion only need to carry out 4 to 8 assignment operations, and the concise and assignment number of operation is few, it is simple to calculate, and greatly carries Speed of the IP address conversion at character string is risen.
Description of the drawings
By reading a detailed description of non-restrictive embodiments in the light of the attached drawings below, of the invention other Feature, objects and advantages will become more apparent upon:
Fig. 1 is a kind of IPV4 address conversion methods flow chart that the embodiment of the present invention one provides;
Fig. 2 is a kind of detailed process flow chart of IPV4 address conversion methods described in Fig. 1;
Fig. 3 is a kind of IPV4 address conversion methods flow chart provided by Embodiment 2 of the present invention;
Fig. 4 is a kind of IPV4 address converting devices structure diagram that the embodiment of the present invention three provides;
Fig. 5 is a kind of concrete structure block diagram of IPV4 address converting devices described in Fig. 4.
Specific implementation mode
The present invention is described in further detail with reference to the accompanying drawings and examples.It is understood that this place is retouched The specific embodiment stated is used only for explaining the present invention rather than limitation of the invention.It also should be noted that in order to just In description, only some but not all contents related to the present invention are shown in the drawings.
Embodiment one
Fig. 1 is a kind of IPV4 address conversion methods flow chart in the embodiment of the present invention one, present embodiments provides one kind IPV4 address conversion methods, this method can be executed by arbitrarily executing the device of IPV4 address conversions, which can pass through Software/or hardware realization.As shown in Figure 1, this method includes:
S110, initialization character string dimension corresponding with the number of the addresses IPV4;
Provide that IP address length is 32, that is, has 2^32-1=255 address in IPV4, so initializing an overall situation here Length be 255 character string dimension str, with the addresses IPV4 number it is corresponding.By 0 to 255 number, it is respectively set corresponding Character string, and the character string of setting is formed into character string dimension, and the mapping relations of number and character string are established, mapping is closed System is as follows:
Str [0]=" 0 ", str [1]=" 1 " ... ... str [10]=" 10 ", str [100]=" 100 " ... ... str [255]=" 255 ".
So analogize, array global in this way need to only initialize once, so that it may initial to carry out all addresses in IPV4 Change setting, so that it may to use always in a program.
S120, the corresponding number of a byte is extracted from the nybble of the addresses IPV4 successively, and obtains corresponding character String, filling to position corresponding with the byte in transformation result, until the conversion of the addresses IPV4 nybble is completed, after forming conversion Address character string.
Referring to Fig. 2, it is preferred that be based on said program, which includes:
S121, for the addresses IPV4 to be converted, setting pointer is directed toward the first character section of the addresses IPV4, as working as Preceding byte;
Preferably, since the addresses IPV4 include 4 bytes in total, will institute be directed toward as the pointer by first character section from left to right The first character section of the addresses IPV4 is stated, and so on, using the 4th byte from left to right as the end of the addresses IPV4.
S122, the number of the pointer extracting current byte is used;
S123, according to number and the mapping relations of character string, from initialization string array inquiry obtain the number Corresponding character string;
S124, the character string inquired is filled into transformation result position corresponding with the byte;
Preferably, since the addresses IPV4 include in total 4 bytes, the byte is arranged in transformation result to be corresponded 4 positions, such as:First character section corresponding position one, second byte corresponding position two, third byte corresponding position Three, the 4th byte corresponding position four.
S125, mobile pointer, judge whether the end for reaching the addresses IPV4, if so, in the transformation result End mark is arranged in end, forms address character string, if it is not, then returning and being carried described in executing using next byte as current byte Take the operation of the number of current byte.
Preferably, as current byte be nybble, then the end of the transformation result ret be arranged end mark 0, formed Address character string simultaneously returns in the transformation result ret, and otherwise the current locations the transformation result ret are set to ' ', and return Execute the operation of the number of the extraction current byte.
The IPV4 address conversion methods that the embodiment of the present invention one provides, by initialize global character string dimension with Number in IPV4 address bytes is corresponding, and establishes the mapping relations of number and character string, and array global so only needs initially Change primary, so that it may all addresses in IPV4 are carried out Initialize installation, so that it may to use always in a program;In addition, turning When changing IP address, using pointer algorithm, pointer P is made to be directed toward the IP, using pointer P can successively from quadlets at IPV4 it is whole Each byte is extracted in several, can thus pointer be used to transmit address rather than real data, can improve transmission speed Degree, a large amount of memories can be saved by having.
Embodiment two
Fig. 3 is a kind of IPV4 address conversion methods flow chart in the embodiment of the present invention two, the technical solution of the present embodiment Based on above-described embodiment one, make further optimization on the basis of embodiment one.
Further, obtain corresponding character string described, filling to position corresponding with the byte in transformation result it Before, according to the length of the number, determine the assignment type of corresponding character string.The flow specifically includes:
If S310, the number are more than or equal to 100, corresponding character string is split as a character type and one short Integer carries out assignment;
If S320, the number are less than 100 and more than or equal to 10, corresponding character string are assigned a value of short;
If S330, the number are less than 10, corresponding character string is assigned a value of character type.
Illustratively, a character type length is 1 byte, and a short length is 2 bytes.
Such as:If current pointer is directed toward byte, corresponding number is 192,192>100, it is reflected with character string according to number Relationship is penetrated, 192 corresponding character strings " 192 " of number are split into a character type " 1 " and a short " 92 " carries out assignment, Then the transformation result ret length adds 3;
If current pointer is directed toward byte, corresponding number is 71,100>71>10, it is closed according to the mapping of number and character string 71 corresponding character strings " 71 " of number are assigned a value of short by system, and then the transformation result ret length adds 2;
If current pointer is directed toward byte, corresponding number is 1,1<10, then 1 corresponding character string " 1 " of number is assigned a value of Character type, then the transformation result ret length add 1.
IPV4 address conversion methods provided by Embodiment 2 of the present invention determine corresponding character according to the length of the number The assignment type of string, each number, which at most carries out assignment operation twice, can obtain transformation result, assignment method it is concise and Assignment number is few, it is simple to calculate, and conversion every time only needs to carry out 4 to 8 assignment operations, greatly improve IPV4 address conversions at The speed of character string.
Embodiment three
Fig. 4 is a kind of IPV4 address converting devices structure diagram that the embodiment of the present invention three provides.The technology of the present embodiment Scheme is based on above-described embodiment, as shown in figure 4, the IPV4 address converting devices include:
Initialization module 410, for initializing character string dimension corresponding with the number of the addresses IPV4;
Conversion module 420 for extracting the corresponding number of a byte from the nybble of the addresses IPV4 successively, and obtains Corresponding character string, filling to position corresponding with the byte in transformation result, until the conversion of the addresses IPV4 nybble is completed, Form transformed address character string.
On the basis of the above embodiments, initialization module specifically can be used for:By 0 to 255 number, it is respectively set pair The character string answered, and the character string of setting is formed into character string dimension, and establish the mapping relations of number and character string.
On the basis of the above embodiments, conversion module includes:
Pointer unit 421, for for the addresses IPV4 to be converted, setting pointer to be directed toward first of the addresses IPV4 Byte, as current byte;
Extraction unit 422, for the number using the pointer extracting current byte;
Query unit 423, for the corresponding character string of the inquiry acquisition number from initialization string array;
Fills unit 424, for the character string inquired to be filled into transformation result position corresponding with the byte;
Judging unit 425 judges whether the end for reaching the addresses IPV4, if so, described for moving pointer End mark is arranged in the end of transformation result, forms address character string, if it is not, then being returned using next byte as current byte Execute the operation of the number of the extraction current byte.
Further, which further includes assignment module, for obtaining corresponding character string, in filling to transformation result Before position corresponding with the byte, according to the length of the number, the assignment type of corresponding character string is determined.
On the basis of the above embodiments, assignment module is specifically used for:
If the number is more than or equal to 100, corresponding character string is split as a character type and a short Carry out assignment;
If the number is less than 100 and more than or equal to 10, corresponding character string is assigned a value of short shaping;
If the number is less than 10, corresponding character string is assigned a value of character type.
The IPV4 address converting devices that the embodiment of the present invention is provided are for executing IPV4 provided in an embodiment of the present invention Location conversion method has corresponding function and advantageous effect.
Note that above are only presently preferred embodiments of the present invention and institute's application technology principle.It will be appreciated by those skilled in the art that The present invention is not limited to specific embodiments described here, can carry out for a person skilled in the art it is various it is apparent variation, It readjusts and substitutes without departing from protection scope of the present invention.Therefore, although being carried out to the present invention by above example It is described in further detail, but the present invention is not limited only to above example, without departing from the inventive concept, also May include other more equivalent embodiments, and the scope of the present invention is determined by scope of the appended claims.

Claims (6)

1. a kind of IPV4 address conversion methods, which is characterized in that including:
Initialize character string dimension corresponding with the number of the addresses IPV4;
The corresponding number of a byte is extracted from the nybble of the addresses IPV4 successively, and obtains corresponding character string, filling is extremely Position corresponding with the byte in transformation result forms transformed address word until completing the conversion of the addresses IPV4 nybble Symbol string;
Obtain corresponding character string further includes before filling to position corresponding with the byte in transformation result:
According to the length of the number, the assignment type of corresponding character string is determined;
According to the length of the number, determine that the assignment type of corresponding character string includes:
If the number is more than or equal to 100, corresponding character string is split as a character type and a short carries out Assignment;
If the number is less than 100 and more than or equal to 10, corresponding character string is assigned a value of short;
If the number is less than 10, corresponding character string is assigned a value of character type.
2. according to the method described in claim 1, it is characterized in that, a byte is extracted from the nybble of the addresses IPV4 successively Corresponding number, and corresponding character string is obtained, filling to position corresponding with the byte in transformation result, until completing IPV4 The conversion of address nybble, forming transformed address character string includes:
For the addresses IPV4 to be converted, setting pointer is directed toward the first character section of the addresses IPV4, as current byte;
Use the number of the pointer extracting current byte;
Inquiry obtains the corresponding character string of the number from initialization string array;
The character string inquired is filled into transformation result position corresponding with the byte;
Mobile pointer, judges whether the end for reaching the addresses IPV4, if so, knot is arranged at the end of the transformation result Beam accords with, and forms address character string, if it is not, then returning using next byte as current byte and executing the extraction current byte Number operation.
3. according to the method described in claim 1, it is characterized in that, initialization character string number corresponding with the number of the addresses IPV4 Group includes:
By 0 to 255 number, corresponding character string is respectively set, and the character string of setting is formed into character string dimension, and Establish the mapping relations of number and character string.
4. a kind of IPV4 address converting devices, which is characterized in that including:
Initialization module, for initializing character string dimension corresponding with the number of the addresses IPV4;
Conversion module for extracting the corresponding number of a byte from the nybble of the addresses IPV4 successively, and obtains corresponding Character string, filling to position corresponding with the byte in transformation result form and turn until completing the conversion of the addresses IPV4 nybble Address character string after changing;
Assignment module, for obtaining corresponding character string, before filling to position corresponding with the byte in transformation result, root According to the length of the number, the assignment type of corresponding character string is determined;
The assignment module is specifically used for:
If the number is more than or equal to 100, corresponding character string is split as a character type and a short carries out Assignment;
If the number is less than 100 and more than or equal to 10, corresponding character string is assigned a value of short;
If the number is less than 10, corresponding character string is assigned a value of character type.
5. device according to claim 4, which is characterized in that the conversion module includes:
Pointer unit, for for the addresses IPV4 to be converted, setting pointer to be directed toward the first character section of the addresses IPV4, makees For current byte;
Extraction unit, for the number using the pointer extracting current byte;
Query unit, for the corresponding character string of the inquiry acquisition number from initialization string array;
Fills unit, for the character string inquired to be filled into transformation result position corresponding with the byte;
Judging unit judges whether the end for reaching the addresses IPV4, if so, in the Change-over knot for moving pointer End mark is arranged in the end of fruit, forms address character string, if it is not, then returning using next byte as current byte and executing institute State the operation of the number of extraction current byte.
6. device according to claim 4, which is characterized in that the initialization module is specifically used for:
By 0 to 255 number, corresponding character string is respectively set, and the character string of setting is formed into character string dimension, and Establish the mapping relations of number and character string.
CN201510494185.0A 2015-08-12 2015-08-12 A kind of IPV4 address conversion methods and device Active CN105187568B (en)

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 CN105187568A (en) 2015-12-23
CN105187568B true 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 (5)

* Cited by examiner, † Cited by third party
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
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

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2012156957A (en) * 2011-01-28 2012-08-16 Hitachi Ltd Network system, control device, computer and network device

Patent Citations (5)

* Cited by examiner, † Cited by third party
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
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)

* Cited by examiner, † Cited by third party
Title
IP地址字符串与整数的互相转化转换;unimen;《blog.csdn.net/unimen/article/details/6844456》;20111004;第1-2页 *

Also Published As

Publication number Publication date
CN105187568A (en) 2015-12-23

Similar Documents

Publication Publication Date Title
Mayer et al. Emufog: Extensible and scalable emulation of large-scale fog computing infrastructures
CN109347881B (en) Network protection method, device, equipment and storage medium based on network spoofing
CN103176833B (en) A kind of data transmission method for uplink based on virtual machine, method of reseptance and system
CN105162674A (en) Method and network card for physical machine to access to virtual network
CN107066340B (en) LINUX-based uninterrupted line speed packet receiving and transmitting method and equipment
CN111355686B (en) Method, device, system and storage medium for defending flood attacks
CN112883377A (en) Feature countermeasure based federated learning poisoning detection method and device
JP2014179025A (en) Connection destination information extraction device, connection destination information extraction method, and connection destination information extraction program
CN102811158A (en) Data positioning and recombining method and corresponding device
CN104852921A (en) Test system and method for protecting open port from attacking for network equipment
CN105187568B (en) A kind of IPV4 address conversion methods and device
CN112866036B (en) Network flow simulation method and system of cloud computing platform and computer storage medium
CN104702707A (en) Method and device for data processing
CN107547690A (en) Port assignment method, apparatus, NAT device and storage medium in NAT
CN112235436A (en) Network address translation rule matching method and equipment
Hoerdt et al. Completeness of the internet core topology collected by a fast mapping software
CN106027554A (en) Hacker tool mining method, device and system
CN109446146A (en) A kind of state transition sequence generation method of application layer communication protocol
KR100639568B1 (en) An apparatus for a performance test of information security system using network processor and a method thereof
CN109818834B (en) Lightweight SDN flow table rule detection tool and detection method
CN106790295B (en) Method based on grey forecasting model detection distributed denial of service network attack
CN112995353A (en) IPv6 address survivability scanning system and method based on flow analysis
KR102079028B1 (en) Apparatus and method for generating simulated network traffic traces
CN112583832A (en) DPI-based application layer protocol identification method and system
CN111814161A (en) Data transmission method and system

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