Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The ip of python's ipv4 is converted into an int value.
The ip of python's ipv4 is converted into an int value.
Recently, it is necessary to check the repeatability of ip input by users at work. Before, all ip was processed, and only through ip string comparison. Now the user enters ip+ mask, which means that the input of ip range is supported, and the previous verification method will not work.

So how to solve it? We all know that ip4 is expressed in dotted decimal system and is essentially a binary integer. We only need to convert IP expressed in decimal into binary integers and compare them with numerical values.

For a single ip, it is directly converted into an integer. For the form of ip+ mask (that is, ip range), the starting value and ending value of the range can be obtained to determine its range.

Here is the introduction as follows:

The network address is the starting value of the ip segment and the broadcast address is the ending value of the ip segment.

Like it, like it! ! !