CN117119441A - IP address allocation method, device, server and storage medium - Google Patents
IP address allocation method, device, server and storage medium Download PDFInfo
- Publication number
- CN117119441A CN117119441A CN202311185793.4A CN202311185793A CN117119441A CN 117119441 A CN117119441 A CN 117119441A CN 202311185793 A CN202311185793 A CN 202311185793A CN 117119441 A CN117119441 A CN 117119441A
- Authority
- CN
- China
- Prior art keywords
- address
- value
- bit
- state value
- segment
- 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.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 54
- 238000012163 sequencing technique Methods 0.000 claims description 6
- 230000008569 process Effects 0.000 claims description 4
- 238000004891 communication Methods 0.000 description 12
- 238000013461 design Methods 0.000 description 8
- 238000010586 diagram Methods 0.000 description 4
- 230000003068 static effect Effects 0.000 description 4
- 238000004590 computer program Methods 0.000 description 3
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 238000012545 processing Methods 0.000 description 3
- 230000000694 effects Effects 0.000 description 2
- 230000006870 function Effects 0.000 description 2
- 238000010295 mobile communication Methods 0.000 description 2
- 238000011161 development Methods 0.000 description 1
- 238000000802 evaporation-induced self-assembly Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04W—WIRELESS COMMUNICATION NETWORKS
- H04W8/00—Network data management
- H04W8/26—Network addressing or numbering for mobility support
-
- 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/50—Address allocation
- H04L61/5007—Internet protocol [IP] addresses
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Databases & Information Systems (AREA)
- Small-Scale Networks (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The application provides an IP address allocation method, an IP address allocation device, a server and a storage medium, wherein the method comprises the following steps: aiming at any IP address segment, obtaining an IP address bitmap corresponding to the IP address segment; for the first bit with the subscript value of 0 in the IP address bitmap, if the corresponding IP address is allocated, setting the state value of the first bit as a second state value; continuing traversing the state value of each bit in the IP address bitmap according to the ordering of the index values, and executing the following steps: determining a first target bit having a last state value being a second state value; judging whether the lower standard value of the first target bit is smaller than the length of the IP address field after the interval value 1 is added; if yes, distributing the IP address corresponding to the bit after the lower index value of the first target bit is added with the interval value 1 to the equipment end; if not, outputting the prompt message that the IP address segments are distributed, so that the efficiency of distributing the IP addresses by the bitmap system is higher, and the same IP address cannot be distributed repeatedly.
Description
Technical Field
The present application relates to the field of computer technologies, and in particular, to an IP address allocation method, an apparatus, a server, and a storage medium.
Background
In the field of mobile communications, SIM cards provide network connectivity and data transfer functions. When using SIM cards for data communication, each SIM card needs to be assigned an IP address. The IP address is a unique digital identifier for identifying the network device for communication and data exchange between the communication devices.
In the prior art, a Mysql database is generally used to perform an allocation operation on an IP address. Typically, each time an IP address is assigned, it is necessary to check whether each IP address in the Mysql database is occupied, and if any IP address is not occupied, it may be assigned to a SIM card.
However, in the prior art, since each IP address of the Mysql database needs to be checked during each allocation, the system allocation efficiency is low, and the problem of repeated allocation of the same IP address easily occurs.
Disclosure of Invention
The application provides an IP address allocation method, an IP address allocation device, a server and a storage medium, which allocate IP addresses to SIM cards or devices through a Redis bitmap, so that the allocation efficiency of a bitmap system is higher, and the problem of repeated allocation of the same IP addresses does not occur.
In a first aspect, the present application provides an IP address allocation method, applied to a server, including:
for any IP address segment, obtaining an IP address bitmap corresponding to the IP address segment, wherein each IP address in the IP address bitmap corresponds to one bit, each bit corresponds to one index value and one state value, wherein the index value of each bit corresponding to each IP address in the IP address segment is increased by an interval value of 1 from 0, and the state value corresponding to each bit is a first state value indicating that the corresponding IP address is not allocated or a second state value indicating that the corresponding IP address is allocated;
for a first bit with a subscript value of 0, if a corresponding IP address is allocated, setting a state value of the first bit as a second state value;
continuing traversing the state value of each bit in the IP address bitmap according to the ordering of the index values, and executing the following steps:
determining a first target bit having a last state value being a second state value; if the length of the IP address segment is smaller than that of the first target bit after the interval value 1 is added to the lower standard value of the first target bit, distributing the IP address corresponding to the bit after the interval value 1 is added to the lower standard value of the first target bit to the equipment end, and setting the first state value as the second state value; and if the lower standard value of the first target bit is not smaller than the length of the IP address segment after being added with the preset interval number, outputting a prompt message that the IP address segment is distributed.
In one possible design, after the outputting the alert message that the IP address segments are all allocated, the method further includes: acquiring an IP address of a first order bit in a plurality of IP addresses released by a first equipment end as a first IP address, inquiring an IP address field to which the plurality of IP addresses belong, and acquiring an IP address bitmap corresponding to the IP address field; determining a first offset of the first IP address in the IP address field in the IP address bitmap; determining a second target bit of the first IP address in the IP address bitmap according to the first offset, and resetting a second state value of the second target bit to be a first state bit value; distributing the first IP address to a second equipment end, and setting a first state value of the second target bit as a second state value; if the lower standard value of the second target bit plus the interval value 1 is smaller than the length of the IP address segment, traversing the rest released IP addresses of the first equipment end, and taking the rest released IP addresses as second IP addresses; distributing the second IP address to a second equipment end, and setting a first state bit value of a target bit corresponding to the second IP address as a second state value; and if the lower standard value of the second target bit plus the interval value 1 is not smaller than the length of the IP address segment, outputting a prompt message that the IP address segments are distributed.
In one possible design, the determining, in the IP address bitmap, the first offset of the first IP address in the IP address field includes: setting the address value of the initial IP address in the IP address field as a first address number, and setting the difference value of the address values of any two adjacent IP addresses in the IP address field as a preset interval number; acquiring an address value of the first IP address and taking the address value as a second address value; determining the total offset of the first IP address in the IP address field according to the difference value of the second address number and the first address number; and determining the first offset according to the ratio of the total offset to the preset interval number.
In one possible design, the method further comprises: acquiring a designated IP address to be allocated, inquiring an IP address segment to which the designated IP address belongs, and acquiring an IP address bitmap corresponding to the IP address segment; determining a second offset of the specified IP address in the IP address field in the IP address bitmap; determining a third target bit of the specified IP address in the IP address bitmap according to the second offset, and judging whether the state value of the third target bit can be set as a second state value; if the state value of the third target bit can be set to the second state value, the appointed IP address is distributed to the equipment end; if the state value of the third target bit cannot be set to the second state value, allocating an unassigned IP address to the equipment according to the order of the IP addresses in the IP address field.
In one possible design, after said querying the IP address segment to which the specified IP address belongs, the method further includes: if the IP address segment to which the appointed IP address belongs is not inquired, outputting prompt information of failure in distributing the appointed IP address to the user side.
In one possible design, this further includes the process of creating an IP address bitmap, as follows: any IP address segment to be allocated is obtained, wherein the IP address segment to be allocated comprises a plurality of IP addresses; incrementally sorting the plurality of IP addresses according to the address values; setting a bit for each IP address after incremental sequencing, wherein each bit comprises a subscript value and a state value; sequentially starting to increase and set the subscript value of the bit corresponding to each IP address after increasing and sequencing according to 0 by using an interval value of 1; the state value of the bit corresponding to each IP address is set to the first state value to which the IP address is not assigned.
In one possible design, the IP address field includes: an IP address segment sequence number, a start IP address and an end IP address; wherein the IP address field sequence numbers are used to identify different IP address fields.
In a second aspect, the present application provides an IP address allocation apparatus, applied to a server, including:
a first obtaining module, configured to obtain, for any IP address segment, an IP address bitmap corresponding to the IP address segment, where each IP address in the IP address bitmap corresponds to a bit, each bit corresponds to a subscript value and a status value, where the subscript value of each bit corresponding to each IP address in the IP address segment is incremented by an interval value 1 from 0, where the status value corresponding to each bit is a first status value indicating that the corresponding IP address is not allocated or a second status value indicating that the corresponding IP address is allocated;
the first setting module is used for setting a state value of a first bit with a subscript value of 0 as a second state value if a corresponding IP address is allocated;
the traversing module is used for continuously traversing the state value of each bit in the IP address bitmap according to the sequence of the index values, and executing the following steps:
determining a first target bit having a last state value being a second state value; if the length of the IP address segment is smaller than that of the first target bit after the interval value 1 is added to the lower standard value of the first target bit, distributing the IP address corresponding to the bit after the interval value 1 is added to the lower standard value of the first target bit to the equipment end, and setting the first state value as the second state value; and if the lower standard value of the first target bit is not smaller than the length of the IP address segment after being added with the preset interval number, outputting a prompt message that the IP address segment is distributed.
In a third aspect, the present application provides a server comprising: at least one processor and memory;
the memory stores computer-executable instructions;
the at least one processor executes the computer-executable instructions stored by the memory, causing the at least one processor to perform the IP address allocation method as described above in the first aspect and the various possible designs of the first aspect.
In a fourth aspect, the present application provides a computer storage medium having stored therein computer-executable instructions which, when executed by a processor, implement the IP address allocation method according to the first aspect and the various possible designs of the first aspect.
The application provides an IP address allocation method, a device, a server and a storage medium, wherein after an IP address corresponding to a first bit with a subscript value of 0 is allocated, a first target bit with a last state value of a second state value is determined; judging whether the lower standard value of the first target bit is smaller than the length of the IP address field after the interval value 1 is added; if yes, distributing the IP address corresponding to the bit after the lower index value of the first target bit is added with the interval value 1 to the equipment end; if not, outputting the prompt message that the IP address segments are distributed, so that the efficiency of distributing the IP addresses by the bitmap system is higher, and the problem of repeated distribution of the same IP addresses does not occur.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions of the prior art, the drawings that are needed in the embodiments or the description of the prior art will be briefly described below, it will be obvious that the drawings in the following description are some embodiments of the present application, and that other drawings can be obtained according to these drawings without inventive effort to a person skilled in the art.
Fig. 1 is a schematic diagram of an application scenario of an IP address allocation method according to an embodiment of the present application;
fig. 2 is a schematic flow chart of an IP address allocation method according to an embodiment of the present application;
fig. 3 is a schematic flow chart of a method for IP address allocation according to an embodiment of the present application;
fig. 4 is a flowchart of a third embodiment of an IP address allocation method according to the present application;
fig. 5 is a schematic flow chart of an IP address allocation method according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of an IP address allocation apparatus according to an embodiment of the present application;
fig. 7 is a schematic hardware structure of a server according to an embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
With the continuous development of communication network technology, the application of IP addresses has also progressed tremendously. Currently, when using SIM cards for data communication, each SIM card needs to be assigned an IP address, and the IP address is a unique digital identifier for identifying network devices, so that communication and data exchange between communication devices can be performed. Where the IP address of the SIM card is typically temporary, which means that a different IP address may be assigned each time a connection is made to the network. The IP address of a SIM card may not only vary from card to card, but may also vary in different network environments. For example, different IP addresses may be assigned when using a SIM card for communication in different geographical locations or in different networks of mobile network operators. In the conventional technology, a Mysql database is generally used to perform an IP address allocation operation. Each time an IP address is allocated, it needs to check whether each IP address in the Mysql database is occupied, and if any IP address is not occupied, it can be allocated to a SIM card. However, since each IP address of the Mysql database needs to be checked at each allocation, the system allocation efficiency is low, and the problem of repeated allocation of the same IP address easily occurs.
In order to solve the above technical problems, the embodiments of the present application provide the following technical ideas: the inventor considers the shortcoming of the prior Mysql database that the related IP address allocation operation is carried out, and carries out static IP address sequence allocation, static released IP address allocation and specified IP address allocation for the SIM card or the equipment based on the Redis bitmap, so that the efficiency of allocating the IP address by the bitmap system is higher, and the problem of repeated allocation of the same IP address does not occur.
Fig. 1 is an application scenario schematic diagram of an IP address allocation method provided in an embodiment of the present application.
As shown in fig. 1, the scene includes: a display terminal 101 and a server 102.
The display terminal 101 may be a display screen or a terminal such as a personal computer.
The server 102 may be a single server or a cluster of multiple servers.
The display terminal 101 receives the allocation information of the IP address in the IP address field, and transmits the allocation information of the IP address to the server 102 through the wireless network. The server 102 allocates an unassigned IP address in the IP address field to the SIM card or the device according to the allocation situation of the IP address, and outputs a prompt message according to whether the IP address is allocated successfully. The following will explain in detail the embodiments.
Example 1
Fig. 2 is a schematic flow chart of an IP address allocation method according to an embodiment of the present application, where the execution subject of the embodiment may be a server in the embodiment shown in fig. 1, and the embodiment is not limited herein.
As shown in fig. 2, the method includes:
s201: and aiming at any IP address segment, acquiring an IP address bitmap corresponding to the IP address segment, wherein each IP address in the IP address bitmap corresponds to one bit, each bit corresponds to one subscript value and one state value, the subscript value of each bit corresponding to each IP address in the IP address segment is increased by an interval value of 1 from 0, and the state value corresponding to each bit is a first state value indicating that the corresponding IP address is not allocated or a second state value indicating that the corresponding IP address is allocated.
In this embodiment, the IP address field includes: an IP address segment sequence number, a start IP address and an end IP address; wherein the IP address field sequence numbers are used to identify different IP address fields.
Wherein the IP address is an internet protocol address and has uniqueness.
In this embodiment, the IP address bitmap may be a dis bitmap, or may be another bitmap; furthermore, the IP address bitmap can be regarded as a one-dimensional map.
In this embodiment, the first state value may be any one of 0, 2 or 4, and the second state value may be any one of 1, 3 or 5, and the first state value and the second state value may also take other values, which are not particularly limited herein. Illustratively, the first state value is 0 and the second state value is 1.
S202: for the first bit with subscript value 0, if the corresponding IP address is assigned, the state value of the first bit is set to the second state value.
In this embodiment, the discussion about the first state value and the second state value is already described in detail in step S201, and will not be repeated here.
S203: continuing traversing the state value of each bit in the IP address bitmap according to the ordering of the index values, and executing the following steps:
determining a first target bit having a last state value being a second state value; if the length of the lower standard value of the first target bit added with the interval value 1 is smaller than the length of the IP address segment, distributing the IP address corresponding to the bit after the lower standard value of the first target bit added with the interval value 1 to the equipment end, and setting the first state value as the second state value; and if the lower standard value of the first target bit is not less than the length of the IP address segment after being added with the preset interval number, outputting a prompt message that the IP address segment is distributed.
In this embodiment, the device side may be a communication device, a network device, or other devices. In addition to the device, it may be a SIM card, a virtual phone card, or other communication card.
The mobile communication device may also contain a plurality of SIM cards, such as a cell phone.
In summary, in the IP address allocation method provided in this embodiment, after the IP address corresponding to the first bit with the subscript value of 0 is allocated, the first target bit with the last state value of the second state value is determined; judging whether the lower standard value of the first target bit is smaller than the length of the IP address field after the interval value 1 is added; if yes, distributing the IP address corresponding to the bit after the lower index value of the first target bit is added with the interval value 1 to the equipment end; if not, outputting the prompt message that the IP address segments are distributed, so that the efficiency of distributing the IP addresses by the bitmap system is higher, and the problem of repeated distribution of the same IP addresses does not occur.
Fig. 3 is a schematic flow chart of an IP address allocation method according to an embodiment of the present application. In the embodiment of the present application, the process of creating the IP address bitmap before step S201 is described in detail on the basis of the embodiment provided in fig. 2. As shown in fig. 3, the method includes:
s301: and obtaining any IP address segment to be allocated, wherein the IP address segment to be allocated comprises a plurality of IP addresses.
In this embodiment, the discussion about the IP address and the IP address segment is already described in detail in step S201, and will not be repeated here.
S302: the plurality of IP addresses are incrementally ordered according to the address value.
In this embodiment, the address value is a value converted from an IP address.
S303: each IP address after incremental ordering is set with a bit, each bit comprising a subscript value and a status value.
S304: and sequentially starting to increase and set the subscript value of the bit corresponding to each IP address after increasing and sequencing according to 0 by using an interval value of 1.
For example, if the IP address segment is set to include 10 IP addresses, the subscript value of the bit corresponding to each IP address is sequentially set to be increased by an interval value of 1 starting with 0: 0. 1, 2, 3, 4, 5, 6, 7, 8 and 9.
S305: the state value of the bit corresponding to each IP address is set to the first state value to which the IP address is not assigned.
In this embodiment, the discussion about the first state value is already described in detail in step S201, and will not be repeated here.
Example two
Fig. 4 is a flowchart illustrating a third IP address allocation method according to an embodiment of the present application. In the embodiment of the present application, the process of allocating the released static IP address to the device side after step S203 is described in detail on the basis of the embodiment provided in fig. 2. As shown in fig. 4, the method includes:
s401: the method comprises the steps of obtaining an IP address with a first order from a plurality of IP addresses released by a first equipment end as a first IP address, inquiring an IP address segment to which the plurality of IP addresses belong, and obtaining an IP address bitmap corresponding to the IP address segment.
In this embodiment, the first device side is at least one device. The first device side may release one IP address, or may release multiple IP addresses.
S402: a first offset of the first IP address in the IP address field is determined in the IP address bitmap.
Specifically, step S402 specifically includes:
s4021: setting the address value of the initial IP address in the IP address field as a first address number, and setting the difference value of the address values of any two adjacent IP addresses in the IP address field as a preset interval number.
In this embodiment, the address value is a value converted from an IP address, and the address value of each IP address in the IP address field is preset according to the address value of the starting IP address and the preset interval number.
Wherein the address value of the starting IP address may be translated to a 1, 3, 5 or other value.
In this embodiment, the preset interval number may be any one of 1, 2, or 3, or may be other numbers.
S4022: and obtaining the address value of the first IP address and taking the address value as the second address value.
In this embodiment, the address value is described in detail in step S302, and will not be described here again.
S4023: and determining the total offset of the first IP address in the IP address field according to the difference value of the second address number and the first address number.
S4024: and determining the first offset according to the ratio of the total offset to the preset interval number.
Illustratively, if the difference between the second address number and the first address number is 5, then the total offset of the first IP address in the IP address field is determined to be 5.
If the preset interval number is 1, the ratio of the total offset to the preset interval number is 5, i.e. the first offset is 5. Wherein the first offset indicates that the first released IP address is offset by 5 IP addresses in the IP address field.
S403: and determining a second target bit of the first IP address in the IP address bitmap according to the first offset, and resetting a second state value of the second target bit to be the first state bit value.
In this embodiment, the discussion about the first state value and the second state value is already described in detail in step S201, and will not be repeated here.
S404: the first IP address is allocated to the second equipment end, and the first state value of the second target bit is set to be the second state value.
S405: if the lower standard value of the second target bit plus the interval value 1 is smaller than the length of the IP address segment, traversing the rest released IP address of the first equipment end, and taking the rest released IP address as a second IP address; distributing the second IP address to a second equipment end, and setting a first state bit value of a target bit corresponding to the second IP address as a second state value; and if the lower standard value of the second target bit plus the interval value 1 is not smaller than the length of the IP address segment, outputting a prompt message that the IP address segments are distributed.
In this embodiment, the second device side is at least one or more devices, and the second IP address corresponds to at least one target bit.
In summary, in the IP address allocation method provided in this embodiment, a plurality of IP addresses released by a first device side are obtained, and the IP address with the first order is used as a first IP address; determining a first offset of the first IP address in the IP address field in the IP address bitmap, determining a second target bit of the first IP address in the IP address bitmap, and distributing the first IP address to the second equipment end; judging whether the lower standard value of the second target bit plus the interval value 1 is smaller than the length of the IP address segment; if yes, traversing the rest released IP addresses of the first equipment end, and distributing the rest released IP addresses to the second equipment end; if not, outputting prompt information that the IP address segments are distributed completely, so that the IP address resources can be fully utilized, and the resource waste is reduced.
Example III
Fig. 5 is a flowchart of an IP address allocation method according to an embodiment of the present application. The execution body of the present embodiment may be a server in the embodiment shown in fig. 1, and the present embodiment is not particularly limited here. As shown in fig. 5, this embodiment describes in detail a flow of assigning a specified IP address to a device side, and the method includes:
s501: acquiring a designated IP address to be allocated, inquiring an IP address segment to which the designated IP address belongs, and acquiring an IP address bitmap corresponding to the IP address segment.
In this embodiment, if the IP address field to which the specified IP address belongs is not found in step S501, a prompt message indicating that the user terminal fails to assign the specified IP address is output.
In this embodiment, the discussion about the IP address field and the IP address bitmap is already described in detail in step S201, and will not be repeated here.
The specified IP address may be any IP address in any IP address field.
S502: a second offset of the specified IP address in the IP address field is determined in the IP address bitmap.
In this embodiment, the discussion about the offset determination is already described in detail in the specific step of S402, and will not be repeated here.
S503: and determining a third target bit of the specified IP address in the IP address bitmap according to the second offset, and judging whether the state value of the third target bit can be set to be a second state value.
In the present embodiment, the discussion about the second state value is already described in detail in step S201, and will not be repeated here.
S504: if the state value of the third target bit can be set to be the second state value, the appointed IP address is distributed to the equipment end; if the state value of the third target bit cannot be set to the second state value, an unassigned IP address is assigned to the device according to the ordering of the IP addresses in the IP address field.
In this embodiment, the discussion about the device side is already described in detail in step S203, and will not be repeated here.
In summary, in the IP address allocation method provided in this embodiment, a specified IP address to be allocated is obtained, and a second offset of the specified IP address is determined in an IP address bitmap; determining a third target bit of the designated IP address according to the second offset, and judging whether the state value of the third target bit can be set as a second state value; if yes, the appointed IP address is distributed to the equipment end; if not, an unallocated IP address is allocated to the equipment according to the order of the IP addresses in the IP address segment, so that the bitmap system can accurately allocate the IP addresses.
Fig. 6 is a schematic structural diagram of an IP address allocation apparatus according to an embodiment of the present application. As shown in fig. 6, the IP address allocation apparatus includes: a first acquisition module 601, a first setting module 602, and a traversal module 603.
A first obtaining module 601, configured to obtain, for any IP address segment, an IP address bitmap corresponding to the IP address segment, where each IP address in the IP address bitmap corresponds to a bit, each bit corresponds to a subscript value and a status value, where the subscript value of the bit corresponding to each IP address in the IP address segment is incremented by an interval value 1 from 0, and the status value corresponding to each bit is a first status value indicating that the corresponding IP address is not allocated or a second status value indicating that the corresponding IP address is allocated;
a first setting module 602, configured to set, for a first bit with a subscript value of 0, a state value of the first bit to a second state value if a corresponding IP address is allocated;
the traversing module 603 is configured to continue traversing the status value of each bit in the IP address bitmap according to the ordering of the subscript values, and perform the following steps:
determining a first target bit having a last state value being a second state value; if the length of the IP address segment is smaller than that of the first target bit after the interval value 1 is added to the lower standard value of the first target bit, distributing the IP address corresponding to the bit after the interval value 1 is added to the lower standard value of the first target bit to the equipment end, and setting the first state value as the second state value; and if the lower standard value of the first target bit is not smaller than the length of the IP address segment after being added with the preset interval number, outputting a prompt message that the IP address segment is distributed.
The device provided in this embodiment may be used to implement the technical solution of the foregoing method embodiment, and its implementation principle and technical effects are similar, and this embodiment will not be described herein again.
In one possible implementation, the apparatus further includes:
a second obtaining module 604, configured to obtain, from a plurality of IP addresses released by the first device side, an IP address with a first order as a first IP address, query an IP address field to which the plurality of IP addresses belong, and obtain an IP address bitmap corresponding to the IP address field;
a first determining module 605, configured to determine, in the IP address bitmap, a first offset of the first IP address in the IP address field;
a second determining module 606, configured to determine a second target bit of the first IP address in the IP address bitmap according to the first offset, and reset a second state value of the second target bit to a first state bit value;
a first allocation module 607, configured to allocate the first IP address to a second device side, and set a first state value of the second target bit to a second state value;
a second allocation module 608, configured to traverse the remaining released IP addresses of the first device side and take the remaining released IP addresses as second IP addresses if the subscript value of the second target bit plus the interval value 1 is smaller than the length of the IP address segment; distributing the second IP address to a second equipment end, and setting a first state bit value of a target bit corresponding to the second IP address as a second state value; and if the lower standard value of the second target bit plus the interval value 1 is not smaller than the length of the IP address segment, outputting a prompt message that the IP address segments are distributed.
In one possible implementation, the first determining module 605 includes:
a setting unit 6051 configured to set an address value of a start IP address in the IP address field as a first address number, and set a difference value of address values of any two adjacent IP addresses in the IP address field as a preset interval number;
an acquisition unit 6052 for acquiring an address value of the first IP address as a second address number;
a first determining unit 6053 configured to determine a total offset of the first IP address in the IP address field according to a difference between the second address number and the first address number;
a second determining unit 6054 for determining the first offset according to a ratio of the total offset to the preset interval number.
In one possible implementation, the apparatus further includes:
a query module 609, configured to obtain a specified IP address to be allocated, query an IP address field to which the specified IP address belongs, and obtain an IP address bitmap corresponding to the IP address field;
a third determining module 610, configured to determine, in the IP address bitmap, a second offset of the specified IP address in the IP address field;
a judging module 611, configured to determine a third target bit of the specified IP address in the IP address bitmap according to the second offset, and judge whether a state value of the third target bit can be set to a second state value;
a third allocation module 612, configured to allocate the specified IP address to a device side if the state value of the third target bit can be set to the second state value; if the state value of the third target bit cannot be set to the second state value, allocating an unassigned IP address to the equipment according to the order of the IP addresses in the IP address field.
In one possible implementation, the module further includes: and the output module 613 is configured to output a prompt message indicating that the allocation of the specified IP address to the user terminal fails if the IP address segment to which the specified IP address belongs is not queried.
In one possible implementation, the apparatus further includes:
a third obtaining module 614, configured to obtain any piece of IP address to be allocated, where the piece of IP address to be allocated includes a plurality of IP addresses;
a sorting module 615, configured to sort the plurality of IP addresses incrementally according to the address values;
a second setting module 616 configured to set each of the incrementally ordered IP addresses to a bit, each bit including a subscript value and a status value;
a third setting module 617, configured to sequentially start incremental setting of the subscript value of the bit corresponding to each IP address after incremental sequencing according to 0 and using an interval value of 1;
a fourth setting module 618 is configured to set a status value of a bit corresponding to each IP address to a first status value to which the IP address is not allocated.
In one possible implementation, the IP address field includes: an IP address segment sequence number, a start IP address and an end IP address; wherein the IP address field sequence numbers are used to identify different IP address fields.
The device provided in this embodiment may be used to implement the technical solution of the foregoing method embodiment, and its implementation principle and technical effects are similar, and this embodiment will not be described herein again.
Fig. 7 is a schematic hardware structure of a server according to an embodiment of the present application. As shown in fig. 7, the server of the present embodiment includes: a processor 701 and a memory 702; the memory stores computer-executable instructions; at least one processor executes the computer-executable instructions stored in the memory, causing the at least one processor to perform the IP address assignment method as described above.
Alternatively, the memory 702 may be separate or integrated with the processor 701.
When the memory 702 is provided separately, the server further comprises a bus 703 for connecting said memory 702 to the processor 701.
The embodiment of the application also provides a computer storage medium, wherein computer execution instructions are stored in the computer storage medium, and when a processor executes the computer execution instructions, the IP address allocation method is realized.
The embodiment of the application also provides a computer program product, which comprises a computer program, wherein the computer program realizes the IP address allocation method when being executed by a processor.
In the several embodiments provided by the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described embodiments of the apparatus are merely illustrative, and for example, the division of the modules is merely a logical function division, and there may be additional divisions when actually implemented, for example, multiple modules may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or modules, which may be in electrical, mechanical, or other forms.
The modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical units, may be located in one place, or may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to implement the solution of this embodiment.
In addition, each functional module in the embodiments of the present application may be integrated in one processing unit, or each module may exist alone physically, or two or more modules may be integrated in one unit. The units formed by the modules can be realized in a form of hardware or a form of hardware and software functional units.
The integrated modules, which are implemented in the form of software functional modules, may be stored in a computer readable storage medium. The software functional modules described above are stored in a storage medium and include instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or processor to perform some of the steps of the methods described in the various embodiments of the application.
It should be understood that the above processor may be a central processing unit (Central Processing Unit, abbreviated as CPU), but may also be other general purpose processors, digital signal processors (Digital Signal Processor, abbreviated as DSP), application specific integrated circuits (Application Specific Integrated Circuit, abbreviated as ASIC), etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of a method disclosed in connection with the present application may be embodied directly in a hardware processor for execution, or in a combination of hardware and software modules in a processor for execution.
The memory may comprise a high-speed RAM memory, and may further comprise a non-volatile memory NVM, such as at least one magnetic disk memory, and may also be a U-disk, a removable hard disk, a read-only memory, a magnetic disk or optical disk, etc.
The bus may be an industry standard architecture (Industry Standard Architecture, ISA) bus, an external device interconnect (Peripheral Component Interconnect, PCI) bus, or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, among others. The buses may be divided into address buses, data buses, control buses, etc. For ease of illustration, the buses in the drawings of the present application are not limited to only one bus or to one type of bus.
The storage medium may be implemented by any type or combination of volatile or nonvolatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disk. A storage media may be any available media that can be accessed by a general purpose or special purpose computer.
An exemplary storage medium is coupled to the processor such the processor can read information from, and write information to, the storage medium. In the alternative, the storage medium may be integral to the processor. The processor and the storage medium may reside in an application specific integrated circuit (Application Specific Integrated Circuits, ASIC for short). It is also possible that the processor and the storage medium reside as discrete components in an electronic device or a master device.
Those of ordinary skill in the art will appreciate that: all or part of the steps for implementing the method embodiments described above may be performed by hardware associated with program instructions. The foregoing program may be stored in a computer readable storage medium. The program, when executed, performs steps including the method embodiments described above; and the aforementioned storage medium includes: various media that can store program code, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present application, and not for limiting the same; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some or all of the technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit of the application.
Claims (10)
1. An IP address allocation method, applied to a server, comprising:
for any IP address segment, obtaining an IP address bitmap corresponding to the IP address segment, wherein each IP address in the IP address bitmap corresponds to one bit, each bit corresponds to one index value and one state value, wherein the index value of each bit corresponding to each IP address in the IP address segment is increased by an interval value of 1 from 0, and the state value corresponding to each bit is a first state value indicating that the corresponding IP address is not allocated or a second state value indicating that the corresponding IP address is allocated;
for a first bit with a subscript value of 0, if a corresponding IP address is allocated, setting a state value of the first bit as a second state value;
continuing traversing the state value of each bit in the IP address bitmap according to the ordering of the index values, and executing the following steps:
determining a first target bit having a last state value being a second state value; if the length of the IP address segment is smaller than that of the first target bit after the interval value 1 is added to the lower standard value of the first target bit, distributing the IP address corresponding to the bit after the interval value 1 is added to the lower standard value of the first target bit to the equipment end, and setting the first state value as the second state value; and if the lower standard value of the first target bit is not smaller than the length of the IP address segment after being added with the preset interval number, outputting a prompt message that the IP address segment is distributed.
2. The method of claim 1, further comprising, after said outputting the hint message that the IP address fields are all assigned:
acquiring an IP address of a first order bit in a plurality of IP addresses released by a first equipment end as a first IP address, inquiring an IP address field to which the plurality of IP addresses belong, and acquiring an IP address bitmap corresponding to the IP address field;
determining a first offset of the first IP address in the IP address field in the IP address bitmap;
determining a second target bit of the first IP address in the IP address bitmap according to the first offset, and resetting a second state value of the second target bit to be a first state bit value;
distributing the first IP address to a second equipment end, and setting a first state value of the second target bit as a second state value;
if the lower standard value of the second target bit plus the interval value 1 is smaller than the length of the IP address segment, traversing the rest released IP addresses of the first equipment end, and taking the rest released IP addresses as second IP addresses; distributing the second IP address to a second equipment end, and setting a first state bit value of a target bit corresponding to the second IP address as a second state value; and if the lower standard value of the second target bit plus the interval value 1 is not smaller than the length of the IP address segment, outputting a prompt message that the IP address segments are distributed.
3. The method of claim 2, wherein determining a first offset of the first IP address in the IP address field in the IP address bitmap comprises:
setting the address value of the initial IP address in the IP address field as a first address number, and setting the difference value of the address values of any two adjacent IP addresses in the IP address field as a preset interval number;
acquiring an address value of the first IP address and taking the address value as a second address value;
determining the total offset of the first IP address in the IP address field according to the difference value of the second address number and the first address number;
and determining the first offset according to the ratio of the total offset to the preset interval number.
4. The method as recited in claim 1, further comprising:
acquiring a designated IP address to be allocated, inquiring an IP address segment to which the designated IP address belongs, and acquiring an IP address bitmap corresponding to the IP address segment;
determining a second offset of the specified IP address in the IP address field in the IP address bitmap;
determining a third target bit of the specified IP address in the IP address bitmap according to the second offset, and judging whether the state value of the third target bit can be set as a second state value;
if the state value of the third target bit can be set to the second state value, the appointed IP address is distributed to the equipment end; if the state value of the third target bit cannot be set to the second state value, allocating an unassigned IP address to the equipment according to the order of the IP addresses in the IP address field.
5. The method of claim 4, further comprising, after said querying the IP address segment to which the specified IP address belongs:
if the IP address segment to which the appointed IP address belongs is not inquired, outputting prompt information of failure in distributing the appointed IP address to the user side.
6. The method of claim 1, further comprising the process of creating an IP address bitmap as follows:
any IP address segment to be allocated is obtained, wherein the IP address segment to be allocated comprises a plurality of IP addresses;
incrementally sorting the plurality of IP addresses according to the address values;
setting a bit for each IP address after incremental sequencing, wherein each bit comprises a subscript value and a state value;
sequentially starting to increase and set the subscript value of the bit corresponding to each IP address after increasing and sequencing according to 0 by using an interval value of 1;
the state value of the bit corresponding to each IP address is set to the first state value to which the IP address is not assigned.
7. The method according to any one of claims 1 to 6, wherein the IP address field comprises:
an IP address segment sequence number, a start IP address and an end IP address; wherein the IP address field sequence numbers are used to identify different IP address fields.
8. An IP address allocation apparatus, applied to a server, comprising:
a first obtaining module, configured to obtain, for any IP address segment, an IP address bitmap corresponding to the IP address segment, where each IP address in the IP address bitmap corresponds to a bit, each bit corresponds to a subscript value and a status value, where the subscript value of each bit corresponding to each IP address in the IP address segment is incremented by an interval value 1 from 0, where the status value corresponding to each bit is a first status value indicating that the corresponding IP address is not allocated or a second status value indicating that the corresponding IP address is allocated;
the first setting module is used for setting a state value of a first bit with a subscript value of 0 as a second state value if a corresponding IP address is allocated;
the traversing module is used for continuously traversing the state value of each bit in the IP address bitmap according to the sequence of the index values, and executing the following steps:
determining a first target bit having a last state value being a second state value; if the length of the IP address segment is smaller than that of the first target bit after the interval value 1 is added to the lower standard value of the first target bit, distributing the IP address corresponding to the bit after the interval value 1 is added to the lower standard value of the first target bit to the equipment end, and setting the first state value as the second state value; and if the lower standard value of the first target bit is not smaller than the length of the IP address segment after being added with the preset interval number, outputting a prompt message that the IP address segment is distributed.
9. A server, comprising: at least one processor and memory;
the memory stores computer-executable instructions;
the at least one processor executing computer-executable instructions stored in the memory causes the at least one processor to perform the IP address allocation method of any one of claims 1 to 7.
10. A computer storage medium having stored therein computer executable instructions which, when executed by a processor, implement the IP address allocation method of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311185793.4A CN117119441A (en) | 2023-09-14 | 2023-09-14 | IP address allocation method, device, server and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311185793.4A CN117119441A (en) | 2023-09-14 | 2023-09-14 | IP address allocation method, device, server and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117119441A true CN117119441A (en) | 2023-11-24 |
Family
ID=88798291
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311185793.4A Pending CN117119441A (en) | 2023-09-14 | 2023-09-14 | IP address allocation method, device, server and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117119441A (en) |
-
2023
- 2023-09-14 CN CN202311185793.4A patent/CN117119441A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109447820B (en) | Data processing method, device, computer equipment and storage medium | |
CN108845877B (en) | Method, device and system for managing memory | |
CN111064786B (en) | Account identifier management method and device | |
CN112269665B (en) | Memory processing method and device, electronic equipment and storage medium | |
CN111490890A (en) | Hierarchical registration method, device, storage medium and equipment based on micro-service architecture | |
US20170195283A1 (en) | Allocating identifiers with minimal fragmentation | |
CN113672375B (en) | Resource allocation prediction method, device, equipment and storage medium | |
CN113032156A (en) | Memory allocation method and device, electronic equipment and storage medium | |
CN111163186A (en) | ID generation method, device, equipment and storage medium | |
CN110290228B (en) | Internet protocol IP address allocation method and device | |
CN112087401A (en) | Method and device for realizing service quality in distributed storage | |
CN112367256B (en) | Creation method, device and storage medium | |
CN110489356B (en) | Information processing method, information processing device, electronic equipment and storage medium | |
CN117119441A (en) | IP address allocation method, device, server and storage medium | |
CN116467315A (en) | Analysis method, device, equipment and storage medium of behavior data | |
CN116501487A (en) | Task execution method and device on virtual machine, storage medium and electronic equipment | |
CN114327862B (en) | Memory allocation method and device, electronic equipment and storage medium | |
CN115801733A (en) | Network address allocation method and device, electronic equipment and readable medium | |
CN115509749A (en) | Task execution method and device, storage medium and electronic equipment | |
CN110362575B (en) | Method and device for generating global index of data | |
CN113835862B (en) | Task processing method and device | |
CN110046040B (en) | Distributed task processing method and system and storage medium | |
CN111679909A (en) | Data processing method and device and terminal equipment | |
CN106021121B (en) | Packet processing system, method and apparatus to optimize packet buffer space | |
CN117579598B (en) | Method, device, equipment and medium for distributing IP address based on physical network card |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |