如何计算Ip地址在两个Ip地址之间有多少? [英] How to calculate how much Ip Addresses have between two Ip Addresses?
本文介绍了如何计算Ip地址在两个Ip地址之间有多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个Ip地址,我想计算两者之间的Ip地址数。
I have two Ip Addresses, and I want to count how many Ip Addresses there are in the range between the two.
示例:
IP_START = "127.0.0.0"
IP_END = "127.0.1.1"
SUM_OF_IP_ADDRESS = 257
有人知道python是否有任何东西可以帮助我实现这个目标?
Does anyone know if python has anything to help me accomplish this?
推荐答案
使用 ipaddress
包的简短解决方案。
Short solution using the ipaddress
package.
import ipaddress
ip1 = int(ipaddress.IPv4Address(unicode('127.0.0.0')))
ip2 = int(ipaddress.IPv4Address(unicode('127.0.1.1')))
print ip2 - ip1
这篇关于如何计算Ip地址在两个Ip地址之间有多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文