Skip to content

Instantly share code, notes, and snippets.

@gil-obradors
Created January 8, 2019 17:25
Show Gist options
  • Save gil-obradors/87759598f594a295429fcf00b015d976 to your computer and use it in GitHub Desktop.
Save gil-obradors/87759598f594a295429fcf00b015d976 to your computer and use it in GitHub Desktop.
Play python3 csv ipaddress
#!/usr/bin/python3
import csv,ipaddress
with open('IPv4Address.csv', newline='') as csvfile:
data = list(csv.reader(csvfile))
print(data[1][0])
print(type(data))
print(str(ipaddress.IPv4Address(3232235521)))
for i in data:
i[0] = str(ipaddress.IPv4Address(int(i[0]))) + "/32"
i[2] = "Deprecated"
del i[3]
if len(i[1]) == 0:
i[1] = "indefinit"
with open('conversio.csv', 'w') as csvfile2:
wr = csv.writer(csvfile2, doublequote=False, delimiter=',')
for linia in data:
wr.writerow(linia)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment