Py学习  »  Python

a是“0.0.0.0”如何使用内置或任何逻辑python3从0.0.0.0到255.255.255.255的IP组合

kavi Raj • 6 年前 • 1412 次点击  

我尝试使用提供的链接作为副本,但它没有按预期工作 a=‘0.0.0.0’ Z='255.255.255.255' 如何从A-Z IE 0.0.0.0到IP的组合 255.255.255.255使用内置或任何使用python的逻辑

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/33556
 
1412 次点击  
文章 [ 1 ]  |  最新文章 6 年前
Devesh Kumar Singh
Reply   •   1 楼
Devesh Kumar Singh    6 年前

itertools.product 0.0.0.0 255.255.255.255

import itertools

li = range(0,256)

#Generate all possible combinations of numbers from 0 to 255, in a pair of 4
for t in itertools.product(li,repeat=4):
    print(f'{t[0]}.{t[1]}.{t[2]}.{t[3]}')

.....
0.1.121.217
0.1.121.218
0.1.121.219
0.1.121.220
0.1.121.221
0.1.121.222
0.1.121.223
0.1.121.224
......