【发布时间】:2021-01-05 17:16:59
【问题描述】:
python 新手,但试图编写一些东西来检查用户输入的 IP 与 CIDR 是否存在,以查看 IP 在哪个 CIDR 中(如果有)...但是得到某种没有意义的 str 版本错误...
import ipaddress
ip2check = input("Enter IP Address:")
blocks = ['192.1.1.1/8', '0.0.0.0/16']
n = 1
print('Scanning through', len(blocks), 'CIDR blocks')
for x in blocks:
print('Checking', blocks[n])
breakpoint()
if ip2check in ipaddress.IPv4Network(blocks[n]):
print("IP is found in CIDR: ", blocks[n])
else:
print("IP not found in", blocks[n])
错误: 第 11 行,在
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codecs.py(309)init() -> def init(self, errors='strict')
或者它的: AttributeError: 'str' 对象没有属性 '_version'
【问题讨论】:
-
什么错误
-
请粘贴您运行的命令、完整输出和完整堆栈跟踪,没有这些信息很难帮助您
标签: python python-3.x ip-address