Skip to content

Instantly share code, notes, and snippets.

Last active Mar 5, 2020
What would you like to do?
#!/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)) #
#print(ip2int('')) # 167772161

This comment has been minimized.

Copy link
Owner Author

@kosztik kosztik commented Mar 5, 2020

output format:


to .csv

./ -w ./n.dat mmcountry ./n.txt
with mmutils (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment