Disclosure of Invention
In view of the above, the present invention provides a method and a system for dividing a network address segment, so as to quickly, accurately and automatically calculate a network address of each subnet, and complete non-uniform division of the network address segment. The specific scheme is as follows:
a method of network address segment partitioning, comprising:
receiving an IP address, a mask code, a dividing subnet number and a required IP number corresponding to each subnet input by a user;
adding 2 to the required IP number corresponding to each subnet to obtain the actual required IP number corresponding to each subnet;
respectively calculating M which is more than or equal to 2 with minimum actual required IP number corresponding to each subnet[i]Obtaining the distribution IP number corresponding to each subnet by the even number of the power;
subtracting M corresponding to each subnet by using total bits of mask[i]Obtaining the subnet mask length and the subnet mask corresponding to each subnet;
sequencing each subnet according to the sequence of the actual required IP numbers from large to small by using the actual required IP numbers corresponding to each subnet, and generating the sequence of each subnet;
calculating an initial IP by utilizing the IP address and the mask phase, and calculating a broadcast address of the current subnet by utilizing the initial IP, the current subnet and the distributed IP number of all subnets before the current subnet;
and judging whether the sequence of the current subnet is 1, if so, the starting address of the current subnet is equal to the IP address, and if not, the starting address of the current subnet is equal to the broadcasting address of the previous subnet plus 1.
Optionally, the method further includes:
substituting the distributed IP number and the required IP number corresponding to each subnet into an unused IP number calculation formula to calculate the unused IP number corresponding to each subnet;
wherein, the unused IP number calculation formula is as follows:
in the formula, F
[n]Representing the number of unused IPs for subnets in order n,
indicating the allocated IP number, U, of the subnets in order n
nRepresenting the required number of IPs for the subnet in order n.
Optionally, the method further includes:
substituting the sum of the total number of the IP allocable addresses and the allocated IP number allocated to each subnet into a residual IP address number calculation formula according to the sequence of each subnet, and calculating the residual IP address number corresponding to each subnet;
wherein, the remaining IP address number calculation formula is as follows:
in the formula, G[i]Denotes the number of remaining IP addresses of the subnet in order i, and Y denotes the length of the mask.
Optionally, the method further includes:
and obtaining the network segment address corresponding to each subnet by using the starting address and the subnet mask length corresponding to each subnet.
Optionally, the method further includes:
calculating a termination IP by using a termination IP calculation formula;
wherein, the terminating IP calculation formula is: h + X232-Y-1;
Wherein H represents the terminating IP.
Optionally, the method further includes:
and obtaining the assignable IP address range corresponding to each subnet by using the starting address and the broadcast address corresponding to each subnet.
Optionally, the method further includes:
calculating the default gateway corresponding to each subnet by utilizing a default gateway calculation formula and the start address corresponding to each subnet;
wherein the default gateway calculation formula is: e[i]=A[i]+1;
In the formula, E[i]Default gateway, A, representing subnets of order i[i]Indicating the start address of the subnet in order i.
Optionally, the calculating the broadcast address of the current subnet by using the initial IP, the current subnet, and the number of allocated IPs of all subnets before the current subnet, includes:
substituting the initial IP, the current subnet and the distributed IP numbers of all the subnets before the current subnet into a broadcast address calculation formula to calculate the broadcast address of the current subnet;
wherein, the broadcast address calculation formula is:
in the formula, B
[i]Denotes the broadcast address of the subnet in order i, X denotes the starting IP,
the assigned IP number for the subnet with order i.
Optionally, the determining whether the order of the current subnet is 1, if yes, the start address of the current subnet is equal to the IP address, and if no, the start address of the current subnet is equal to the broadcast address of the previous subnet plus 1 includes:
judging whether the sequence of the current subnet is 1 or not by using a starting address calculation formula, if so, the starting address of the current subnet is equal to the IP address, and if not, the starting address of the current subnet is equal to the broadcast address of the previous subnet plus 1;
wherein, the starting address calculation formula is as follows:
in the formula, A[i]Representing the start address of the subnet in order i, IP representing said IP address, B[i-1]Indicating the broadcast addresses of the subnets in order i-1.
The invention also discloses a network address segment dividing system, which comprises:
the receiving module is used for receiving the IP address, the mask code, the divided sub-network number and the required IP number corresponding to each sub-network input by the user;
the actual IP calculating module is used for adding 2 to the required IP number corresponding to each subnet to obtain the actual required IP number corresponding to each subnet;
an IP allocation calculation module for calculating M which is more than or equal to 2 with minimum actual required IP number corresponding to each subnet respectively[i]Obtaining the distribution IP number corresponding to each subnet by the even number of the power;
a subnet mask calculation module for subtracting M corresponding to each subnet by the total number of bits of the mask[i]Obtaining the subnet mask length and the subnet mask corresponding to each subnet;
the subnet order calculation module is used for sequencing each subnet according to the sequence of the actual required IP numbers from large to small by utilizing the actual required IP numbers corresponding to each subnet to generate the order of each subnet;
the broadcast address calculation module is used for calculating an initial IP by utilizing the IP address and the mask phase, and calculating the broadcast address of the current subnet by utilizing the initial IP, the current subnet and the distributed IP number of all subnets before the current subnet;
and the starting address calculation module is used for judging whether the sequence of the current subnet is 1, if so, the starting address of the current subnet is equal to the IP address, and if not, the starting address of the current subnet is equal to the broadcast address of the previous subnet plus 1.
The invention relates to a network address field dividing method, which comprises the following steps: receiving an IP address, a mask code, a dividing subnet number and a required IP number corresponding to each subnet input by a user; adding 2 to the required IP number corresponding to each subnet to obtain the actual required IP number corresponding to each subnet; respectively calculating M which is more than or equal to 2 with minimum actual required IP number corresponding to each subnet[i]Obtaining the distribution IP number corresponding to each subnet by the even number of the power; subtracting M corresponding to each subnet by using total bits of mask[i]Obtaining the subnet mask length and the subnet mask corresponding to each subnet; sequencing each subnet according to the sequence of the actual required IP numbers from large to small by using the actual required IP numbers corresponding to each subnet, and generating the sequence of each subnet; calculating initial IP by using IP address and mask AND, and calculating all sub-networks before current sub-network and current sub-network by using initial IPThe number of distributed IP is calculated, and the broadcast address of the current subnet is calculated; and judging whether the sequence of the current subnet is 1, if so, the starting address of the current subnet is equal to the IP address, and if not, the starting address of the current subnet is equal to the broadcasting address of the previous subnet plus 1.
The invention can obtain the actual required IP number of the subnet through the required IP number of the subnet only by inputting the IP address, the mask, the dividing subnet number and the required IP number respectively corresponding to each subnet by a user, and the minimum 2M of the actual required IP number corresponding to the subnet or more is calculated[i]Obtaining the distributed IP numbers corresponding to the subnets by the even number of the power, and utilizing the total number of the mask and M[i]The method comprises the steps of obtaining the subnet mask length and the subnet mask corresponding to each subnet, generating an order of the subnets according to the actual required IP number from large to small, calculating the broadcast address of the subnet by using the initial IP and the distributed IP number of the subnets, and finally obtaining the start address of the subnet by using the broadcast address and the IP address to finish the division of the network address field of the subnet, thereby realizing the rapid, accurate and automatic calculation of the network address of each subnet and finishing the non-uniform division of the network address field.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment of the invention discloses a network address field dividing method, which comprises the following steps that as shown in figure 1:
step S11: and receiving the IP address, the mask, the divided subnet number and the required IP number corresponding to each subnet input by a user.
For example, the user inputs the IP address of 202.12.3.0, the mask of/24, the number of divided subnets of 5, the number of required IPs for the first subnet of 23, the number of required IPs for the second subnet of 16, the number of required IPs for the third subnet of 56, the number of required IPs for the fourth subnet of 9, and the number of required IPs for the fifth subnet of 13.
It will be appreciated that the initial number of subnets may be generated automatically, in accordance with the user creation order.
Step S12: and adding 2 to the required IP number corresponding to each subnet to obtain the actual required IP number corresponding to each subnet.
Specifically, each subnet needs a broadcast address and a start address, which cannot be directly utilized by the subnet, so that to satisfy the required IP number corresponding to each subnet, 2 needs to be added to the required IP number to represent the broadcast address and the start address of the subnet, and the actual required IP number corresponding to each subnet is obtained, for example, the required IP number of the subnet is 56, and the actual required IP number of the subnet is 58.
Step S13: respectively calculating M which is more than or equal to 2 with minimum actual required IP number corresponding to each subnet[i]And obtaining the distributed IP number corresponding to each subnet by the even number of the power.
It will be appreciated that since the IP address is allocated in 2, if the actual required IP number of the subnet is not a power of 2, the allocated IP number of the subnet will be greater than the actual required IP number of the subnet.
Specifically, after the actual required IP number of the subnet is obtained, the IP number to be allocated to each subnet is calculatedThe number of distributed IP of each subnet is calculated to be more than or equal to M of 2 with the minimum number of actual required IP corresponding to each subnet[i]Even to the power of the power, the respective allocated IP number of each subnet is obtained, for example, the actual required IP number of the subnet is 58, which is at 25And 26I.e., 32 ≦ 58 ≦ 64, so the subnet's assigned IP number is 64, M[i]The value is 6.
Step S14: subtracting M corresponding to each subnet by using total bits of mask[i]And obtaining the subnet mask length and the subnet mask corresponding to each subnet.
Specifically, the total number of bits of the mask, that is, the total length is 32 bits, and the subnet mask of the subnet can be calculated after the subnet mask length of the subnet is known, so that M corresponding to each subnet is subtracted by the total number of bits of the mask[i]Obtaining the subnet mask length and subnet mask corresponding to each subnet, e.g. M of subnet[i]A value of 6, the total number of bits of the mask 32 is used to subtract M of the subnet[i]The subnet mask length of the subnet is 26, and the subnet mask is 255.255.255.192.
Wherein the subnet mask length may be j[i]=32-M[i]Is represented by the formula, wherein j[i]The subnet mask length of the subnet in order i is indicated, and 32 indicates the total number of bits of the mask.
Step S15: and sequencing each subnet according to the sequence of the actual required IP numbers from large to small by using the actual required IP numbers corresponding to each subnet, and generating the sequence of each subnet.
Specifically, since the numbers of the subnets are determined according to the input sequence of the user, it is difficult to ensure that the sequence of the numbers is arranged from large to small according to the actually required IP numbers, and therefore, the actually required IP numbers corresponding to the subnets are utilized to sort the subnets according to the order from large to small of the actually required IP numbers, so as to generate the sequence of the subnets, and avoid the situation that the IP allocation is wasted due to the allocation not according to the sequence, for example, the number of the required IPs for the first subnet is 23, the number of the required IPs for the second subnet is 16, the number of the required IPs for the third subnet is 56, the number of the required IPs for the fourth subnet is 9, and the number of the required IPs for the fifth subnet is 13, the sequence of the third subnet is 1, the sequence of the first subnet is 2, the sequence of the second subnet is 3, the sequence of the fifth subnet is 4, and the sequence of the fourth subnet is 5.
Step S16: and calculating an initial IP by utilizing the IP address and the mask phase, and calculating the broadcast address of the current subnet by utilizing the initial IP, the current subnet and the distributed IP number of all subnets before the current subnet.
Specifically, an IP address and a mask are used to sum up, calculate a starting IP, for example, the IP address is 202.12.3.0, the mask is 255.255.255.0, convert both the IP address and the mask into 2-ary system, sum up 8 bits each, calculate the starting IP to be 202.12.3.0, obtain the starting IP, and then use the starting IP, the current subnet and the allocated IP number of all subnets before the current subnet order, for example, the starting IP is 202.12.3.0, the subnet with the order of 3 is the current subnet, the allocated IP number of the current subnet is 32, the allocated IP number of the subnet with the order of 2 is 32, the allocated IP number of the subnet with the order of 1 is 64, and calculate the broadcast address of the current subnet.
It will be appreciated that the remaining subnets are computed in a manner consistent with the current subnet, thereby computing the broadcast address for each subnet.
Step S17: and judging whether the sequence of the current subnet is 1, if so, the starting address of the current subnet is equal to the IP address, and if not, the starting address of the current subnet is equal to the broadcasting address of the previous subnet plus 1.
Therefore, the embodiment of the invention can obtain the actual required IP number of the subnet through the required IP number of the subnet by only inputting the IP address, the mask, the divided subnet number and the required IP number corresponding to each subnet by the user, and calculate the M [ i ] with the minimum value of 2 which is more than or equal to the actual required IP number corresponding to the subnet]Obtaining the distributed IP numbers corresponding to the subnets by the even number of the power, and utilizing the total number of the mask and M[i]Obtaining the subnet mask length and subnet mask corresponding to each subnet, generating the order of each subnet according to the actual required IP number from large to small, calculating the broadcast address of the subnet by using the initial IP and the distributed IP number of the subnet, and finally using the broadcast placeAnd the address and the IP address are used for obtaining the starting address of the subnet and completing the division of the network address field of the subnet, thereby realizing the rapid, accurate and automatic calculation of the network address of each subnet and completing the non-uniform division of the network address field.
The embodiment of the invention discloses a specific network address field division method, and compared with the previous embodiment, the embodiment further explains and optimizes the technical scheme. Specifically, the method comprises the following steps:
in the embodiment of the present invention, in order to further improve the user experience, the related content of network address segment division may be more comprehensively calculated, and the following steps S21 to S28 may be included; in particular, the method comprises the following steps of,
step S21: and substituting the distributed IP number and the required IP number corresponding to each subnet into an unused IP number calculation formula to calculate the unused IP number corresponding to each subnet.
Wherein, the unused IP number calculation formula is as follows:
in the formula, F
[n]Representing the number of unused IPs for subnets in order n,
indicating the allocated IP number, U, of the subnets in order n
nRepresenting the required number of IPs for the subnet in order n.
E.g. subnets in order of 2, M[n]Is equal to 5, UnEqual to 23 and the unused IP number equal to 7.
Step S22: and substituting the sum of the total number of the IP allocable addresses and the allocated IP number allocated to each subnet into a residual IP address number calculation formula according to the sequence of each subnet, and calculating the residual IP address number corresponding to each subnet.
Wherein, the calculation formula of the residual IP address number is as follows:
in the formula, G[i]Indicating the number of remaining IP addresses of the subnet in order i, YIndicating the length of the mask.
For example, the number of allocated IPs for the subnet in the order of 1 is 64, the number of allocated IPs for the subnet in the order of 2 is 32, the subnet in the order of 3 is the current subnet, the length of the mask is 24, and the remaining IP addresses 128 after the subnet in the order of 3 are obtained by substituting the remaining IP address number calculation formula.
Step S23: and obtaining the network segment address corresponding to each subnet by using the starting address and the subnet mask length corresponding to each subnet.
For example, the subnet has a start address of 202.12.3.0, a subnet mask length of 26, and a segment address of 202.12.3.0/26, i.e., A[i]/j。
Step S24: and calculating the termination IP by using a termination IP calculation formula.
Wherein, the formula for terminating the IP calculation is as follows: h + X232-Y-1;
In the formula, H represents a terminating IP.
For example, the start IP is 202.12.3.0, the mask length is 24, and the stop IP is 202.12.3.255.
Step S27: and obtaining the assignable IP address range corresponding to each subnet by using the starting address and the broadcast address corresponding to each subnet.
Specifically, the assignable IP address range of each subnet is between the start address and the broadcast address corresponding to each subnet, and can be expressed as (a) by using a calculation formula[i]+1 to (B)[i]-1), for example, the subnet has a start address of 202.12.3.0 and the subnet has a broadcast address of 202.12.3.63, the subnet has an allocable IP address range of 202.12.3.1 to 202.12.3.62.
Step S28: and calculating the default gateway corresponding to each subnet by utilizing a default gateway calculation formula and the starting address corresponding to each subnet.
The default gateway calculation formula is as follows: e[i]=A[i]+1;
In the formula, E[i]Default gateway, A, representing subnets of order i[i]Indicating the start address of the subnet in order i.
For example, the start address of a subnet is 202.12.3.64, then the default gateway for that subnet is 202.12.3.65.
In the embodiment of the present invention, the process of calculating the broadcast address of the current subnet by using the initial IP, the current subnet, and the allocated IP numbers of all subnets before the current subnet in sequence described in the previous embodiment may specifically be:
substituting the initial IP, the current subnet and the distributed IP numbers of all the subnets before the current subnet into a broadcast address calculation formula to calculate the broadcast address of the current subnet;
the broadcast address calculation formula is as follows:
in the formula, B
[i]Indicating the broadcast address of the subnet in order i, X indicating the starting IP,
the assigned IP number for the subnet with order i.
In the previous embodiment, the step of determining whether the order of the current subnet is 1, if yes, the start address of the current subnet is equal to the IP address, and if no, the start address of the current subnet is equal to the broadcast address of the previous subnet plus 1 may specifically be:
judging whether the sequence of the current subnet is 1 or not by using a starting address calculation formula, if so, the starting address of the current subnet is equal to the IP address, and if not, the starting address of the current subnet is equal to the broadcast address of the previous subnet plus 1;
wherein, the starting address calculation formula is as follows:
in the formula, A[i]Denotes the start address of the subnet in order i, IP denotes the IP address, B[i-1]Indicating the broadcast addresses of the subnets in order i-1.
Furthermore, in order to facilitate the user to look up the calculation result and improve the user experience, various data can be exported and stored in a form of a table for the user to look up, as shown in the address planning description table in table 1.
TABLE 1
Correspondingly, the embodiment of the present invention also discloses a network address segment dividing system, as shown in fig. 2, the system includes:
a receiving module 11, configured to receive an IP address, a mask, a divided subnet number, and a required IP number corresponding to each subnet, which are input by a user;
an actual IP calculation module 12, configured to add 2 to the required IP number corresponding to each subnet, to obtain an actual required IP number corresponding to each subnet;
an IP allocation calculation module 13 for calculating M which is greater than or equal to 2 with the minimum number of the actual required IP corresponding to each subnet respectively[i]Obtaining the distribution IP number corresponding to each subnet by the even number of the power;
a subnet mask calculating module 14 for subtracting M corresponding to each subnet by the total number of bits of the mask[i]Obtaining the subnet mask length and the subnet mask corresponding to each subnet;
a subnet order calculating module 15, configured to sort each subnet according to a sequence of actual required IP numbers from large to small by using the actual required IP numbers corresponding to each subnet, and generate an order of each subnet;
a broadcast address calculation module 16, configured to calculate an initial IP by using the IP address and the mask phase, and calculate a broadcast address of the current subnet by using the initial IP, the current subnet, and the allocated IP number of all subnets before the current subnet order;
and a start address calculation module 17, configured to determine whether the order of the current subnet is 1, if yes, the start address of the current subnet is equal to the IP address, and if no, the start address of the current subnet is equal to the broadcast address of the previous subnet plus 1.
Therefore, the embodiment of the invention only needs user inputThe IP address, the mask, the dividing subnet number and the required IP number corresponding to each subnet respectively can obtain the actual required IP number of the subnet according to the required IP number of the subnet, and the M which is more than or equal to 2 and has the minimum actual required IP number corresponding to the subnet is calculated[i]Obtaining the distributed IP numbers corresponding to the subnets by the even number of the power, and utilizing the total number of the mask and M[i]The method comprises the steps of obtaining the subnet mask length and the subnet mask corresponding to each subnet, generating an order of the subnets according to the actual required IP number from large to small, calculating the broadcast address of the subnet by using the initial IP and the distributed IP number of the subnets, and finally obtaining the start address of the subnet by using the broadcast address and the IP address to finish the division of the network address field of the subnet, thereby realizing the rapid, accurate and automatic calculation of the network address of each subnet and finishing the non-uniform division of the network address field.
The embodiment of the invention can also comprise:
the unused IP calculation module is used for substituting the distributed IP number and the required IP number which respectively correspond to each subnet into an unused IP number calculation formula to calculate the unused IP number which respectively corresponds to each subnet;
wherein, the unused IP number calculation formula is as follows:
in the formula, F
[n]Representing the number of unused IPs for subnets in order n,
indicating the allocated IP number, U, of the subnets in order n
nRepresenting the required number of IPs for the subnet in order n.
The residual IP calculating module is used for substituting the sum of the total number of the IP allocable addresses and the allocated IP number of each subnet into a residual IP address number calculating formula according to the sequence of each subnet to calculate the residual IP address number corresponding to each subnet;
wherein, the calculation formula of the residual IP address number is as follows:
in the formula, G[i]Denotes the number of remaining IP addresses of the subnet in order i, and Y denotes the length of the mask.
And the network segment address calculation module is used for obtaining the network segment address corresponding to each subnet by utilizing the start address and the subnet mask length corresponding to each subnet.
The terminal IP calculation module is used for calculating a terminal IP by using a terminal IP calculation formula;
wherein, the formula for terminating the IP calculation is as follows: h + X232-Y-1;
In the formula, H represents a terminating IP.
And the address range calculation module is used for obtaining the assignable IP address range corresponding to each subnet by using the starting address and the broadcast address corresponding to each subnet.
In this embodiment of the present invention, the broadcast address module 16 may be specifically configured to substitute the initial IP, the current subnet, and the number of allocated IPs of all subnets before the current subnet order into a broadcast address calculation formula, so as to calculate the broadcast address of the current subnet;
the broadcast address calculation formula is as follows:
in the formula, B
[i]Indicating the broadcast address of the subnet in order i, X indicating the starting IP,
the assigned IP number for the subnet with order i.
The start address calculation module 17 may be specifically configured to determine, by using a start address calculation formula, whether the order of the current subnet is 1, if yes, the start address of the current subnet is equal to the IP address, and if no, the start address of the current subnet is equal to the broadcast address of the previous subnet plus 1;
wherein, the starting address calculation formula is as follows:
in the formula, A[i]Denotes the start address of the subnet in order i, IP denotes the IP address, B[i-1]Indicating the broadcast addresses of the subnets in order i-1.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The method and system for dividing the network address field provided by the present invention are described in detail above, and the principle and the implementation of the present invention are explained in the present document by applying specific examples, and the description of the above embodiments is only used to help understanding the method and the core idea of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.