Last active
March 5, 2020 13:09
-
-
Save kosztik/ee368d35a85cf63f2ac9889474427ec4 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import socket | |
import struct | |
import sys | |
import os | |
def ip2int(addr): | |
return struct.unpack("!I", socket.inet_aton(addr))[0] | |
def int2ip(addr): | |
return socket.inet_ntoa(struct.pack("!I", addr)) | |
filepath = './ip.txt' | |
with open(filepath) as fp: | |
line = fp.readline() | |
cnt = 1 | |
while line: | |
#print("Line {}: {}".format(cnt, line.strip())) | |
line = fp.readline()[:-1] | |
arr = line.split("-") | |
print "\""+arr[0]+"\""+","+"\""+arr[1]+"\",\""+str(ip2int(arr[0]))+"\""+","+"\""+str(ip2int(arr[1]))+"\",\"HU\",\"Hungary\"" | |
#print "\""+str(ip2int(arr[0]))+"\""+","+"\""+str(ip2int(arr[1]))+"\",\"HU\"" | |
cnt += 1 | |
#print(int2ip(0xc0a80164)) # 192.168.1.100 | |
#print(ip2int('174.36.207.186')) # 167772161 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output format:
"2.16.0.0","2.16.5.255","34603008","34604543","EU","Europe"
"2.16.6.0","2.16.7.255","34604544","34605055","DE","Germany"
"2.16.8.0","2.16.67.255","34605056","34620415","EU","Europe"
"2.16.68.0","2.16.69.255","34620416","34620927","SE","Sweden"
"2.16.70.0","2.16.71.255","34620928","34621439","IT","Italy"
to .csv
then
./csv2dat.py -w ./n.dat mmcountry ./n.txt
with mmutils (https://github.com/mteodoro/mmutils)