Найти - Пользователи
Полная версия: Разбить подсеть на диапазоны ip
Начало » Python для новичков » Разбить подсеть на диапазоны ip
1
ss100s
Например 192.168.0.0/13 на
 192.168.0.0-255
192.168.1.0-255
.....
192.175.255.0-254
Может есть библиотека с таким функционалом?
py.user.next
  
>>> import ipaddress
>>> import itertools
>>> 
>>> net = ipaddress.ip_network('192.168.0.0/13')
>>> 
>>> out = []
>>> it = iter(net)
>>> while True:
...     tup = tuple(itertools.islice(it, 0, 256))
...     if not tup:
...         break
...     out.append(tup)
... 
>>> len(out)    
2048
>>> out[0][0], out[0][-1]
(IPv4Address('192.168.0.0'), IPv4Address('192.168.0.255'))
>>> out[1][0], out[1][-1]
(IPv4Address('192.168.1.0'), IPv4Address('192.168.1.255'))
>>> out[2][0], out[2][-1]
(IPv4Address('192.168.2.0'), IPv4Address('192.168.2.255'))
>>>
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB