Skip to content

Instantly share code, notes, and snippets.

@bbopen
Created July 21, 2015 23:16
Show Gist options
  • Save bbopen/10880c029f95dba6f4d0 to your computer and use it in GitHub Desktop.
Save bbopen/10880c029f95dba6f4d0 to your computer and use it in GitHub Desktop.
Take a list (or a csv for that matter) of IP addresses and convert them to integer form. Prints to stdout for flexibility so just use a redirector
import csv
with open('iplist.csv','r') as csvinput:
reader = csv.reader(csvinput)
print('ip_addr,ip_int')
for row in reader:
a,b,c,d = row[0].split('.')
n = (int(a) * 16777216) + (int(b) * 65536) + (int(c) * 256) + int(d)
print(row[0], n, sep=',')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment