【发布时间】:2014-07-03 06:47:00
【问题描述】:
最近,我发现 python 库“iptools”可以帮助我解决一些问题, 但我在 iptools.IpRangeList 遇到问题, i 只能在 first 中声明初始数据,如
internalIP = iptools.IpRangeList(
'127.0.0.1/8',
'192.168/16',
'10.0.0.1/8'
)
如果我想在 IpRangeList 中添加一个新的 ip,编译器总是显示错误
internalIP.append('1.1.1.1')
AttributeError: 'IpRangeList' object has no attribute 'append'
或从文件打开
intranetlist = IpRangeList()
if os.path.isfile("/tmp/intranal.list"):
fp = open("/tmp/intranal.list", 'r')
intranetlist = ([line.strip() for line in fp])
print intranetlist , len(intranetlist)
fp.close()
return
结果: ['127.0.0.1/8', '192.168/16', '10.0.0.0/8'] 3
不正确,正确的结果如下
>>> from iptools import *
>>> a=IpRangeList('127.0.0.1/8' , '192.168/16', '10.0.0.0/8')
>>> print a
(('127.0.0.0', '127.255.255.255'), ('192.168.0.0', '192.168.255.255'), ('10.0.0.0', '10.255.255.255'))
>>> len(a)
33619968
>>>
谁能帮我解决这个问题? 或者有其他我可以使用的库吗?
谢谢。
【问题讨论】: