0

I tried with the links provided as duplicate but its not working as expected A = '0.0.0.0' Z = '255.255.255.255' how to get the combination of ips from A - Z ie 0.0.0.0 to 255.255.255.255 using builtin or any logic using python

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
kavi Raj
  • 211
  • 2
  • 10

1 Answers1

2

You can use itertools.product for this, which generates all possible pairs from 0.0.0.0 to 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]}')

Output will be

.....
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
......
Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40