Skip to content

Instantly share code, notes, and snippets.

View bbopen's full-sized avatar

Brett Bonner bbopen

  • InfoDesk Inc
  • Benicia, CA
View GitHub Profile
@bbopen
bbopen / ip_to_integer.py
Created July 21, 2015 23:16
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=',')