import ipaddress
with open('ip.txt', 'r') as f:
nums = f.read().splitlines()
countlen = (len(nums))
#удаляем содержимое
f2 = open('ips.txt', 'w+')
f2.write('')
f2.close()
i=0
while i<countlen:
for ip in ipaddress.IPv4Network(nums[i]):
f2 = open('ips.txt', 'a')
f2.write(str(ip) + ',')
i+=1
f2.close()