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
Asked
Active
Viewed 248 times
0
-
Not a duplicate i tried those logic in above links but not working. – kavi Raj May 24 '19 at 18:33
1 Answers
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
-
-
accepted it , am not sure someone had told that its duplicate but only your logic worked fine as i wanted and i tried the duplicate link sugg logic but its not working as i want.due to this someone gave negative votes.. – kavi Raj May 24 '19 at 18:40
-
-
Can you please explain your code, because the output does not look correct. Thanks. – Life is complex May 24 '19 at 21:39
-
The explanation is already added, the code generates all possible IP’s . The output I showed is only part of those possible IP’s – Devesh Kumar Singh May 25 '19 at 00:50