【发布时间】:2020-11-09 16:25:07
【问题描述】:
我正在尝试使用以下代码从范围(172.16.3.20 到 192.168.1.1)中获取 ip,但它需要大量时间和 cpu,有时它根本不起作用。有没有更好的方法找到它?所需输出如下:
172.16.3.21
172.16.3.22
...
...
192.167.255.255
192.168.1.1
代码:
start = list(map(int, start_ip.split(".")))
end = list(map(int, end_ip.split(".")))
ip_range = []
temp = start
ip_range.append(start_ip)
while temp != end:
start[3] += 1
for i in (3, 2, 1):
if temp[i] == 256:
temp[i] = 0
temp[i-1] += 1
ip_range.append(".".join(map(str, temp)))
【问题讨论】:
-
是的。谢谢@MrNobody33
标签: python python-3.x ip