Created
July 21, 2015 23:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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