Closed sibarrag closed 8 years ago
Looks like you might be trying to write an org database from a city CSV? Maybe try running it with 'mmcity' in place of 'mmorg'. If you still have issues would you mind pasting the first 10 or so lines of your CSV?
Thanks a lot for your reply!!!
Yes, you are right! My CSV includes city data. Anyway, trying to run it with the option mmcity I got the following result:
Traceback (most recent call last):
File "/Users/admin/PycharmProjects/geoip/csv2dat.py", line 475, in
As you mentioned, here they a few lines of my csv file:
startIpNum,endIpNum,country,region,city,postalCode,latitude,longitude,dmaCode,areaCode
1.0.0.0,1.0.0.255,"AU","","","",-27.0000,133.0000,,
1.0.1.0,1.0.3.255,"CN","","","",35.0000,105.0000,,
1.0.4.0,1.0.4.255,"AU","07","Prahran","3181",-37.8500,145.0000,,
1.0.5.0,1.0.5.255,"AU","07","Melbourne","3000",-37.8232,144.9729,,
1.0.6.0,1.0.7.255,"AU","","","",-27.0000,133.0000,,
1.0.8.0,1.0.15.255,"CN","30","Guangzhou","",23.1167,113.2500,,
1.0.16.0,1.0.31.255,"JP","40","Tokyo","100-0001",35.6850,139.7514,,
1.0.32.0,1.0.63.255,"CN","30","Guangzhou","",23.1167,113.2500,,
1.0.64.0,1.0.79.255,"JP","11","Hiroshima","730-0011",34.3963,132.4594,,
1.0.80.0,1.0.80.255,"JP","31","Okayama","700-0824",34.6617,133.9350,,
1.0.81.0,1.0.83.255,"JP","31","Kurashiki","710-0833",34.5833,133.7667,,
1.0.84.0,1.0.89.255,"JP","31","Okayama","700-0824",34.6617,133.9350,,
1.0.90.0,1.0.91.255,"JP","31","Kurashiki","710-0833",34.5833,133.7667,,
1.0.92.0,1.0.93.255,"JP","31","Okayama","700-0824",34.6617,133.9350,,
1.0.94.0,1.0.94.255,"JP","45","Hofu","747-0801",34.0500,131.5667,,
1.0.95.0,1.0.95.255,"JP","31","Okayama","700-0824",34.6617,133.9350,,
1.0.96.0,1.0.96.127,"JP","45","Yamaguchi","753-0071",34.1858,131.4714,,
1.0.96.128,1.0.96.255,"JP","40","Narimasu","175-0094",35.7837,139.6336,,
Nice, we're getting closer. The MaxMind CSV format that csv2dat.py expects represents IPs as integers, like this:
$ ./csv2dat.py -l GeoLiteCity_20160105/GeoLiteCity-Location.csv flat GeoLiteCity_20160105/GeoLiteCity-Blocks.csv | head
16777216,16777471,AU,,,,-27.0000,133.0000,,
16777472,16778239,CN,,,,35.0000,105.0000,,
16778240,16779263,AU,,,,-27.0000,133.0000,,
16779264,16781311,CN,30,Guangzhou,,23.1167,113.2500,,
16781312,16785407,JP,40,Tokyo,100-0001,35.6850,139.7514,,
16785408,16793599,CN,30,Guangzhou,,23.1167,113.2500,,
16793600,16798975,JP,11,Hiroshima,730-0011,34.3963,132.4594,,
16798976,16799231,JP,31,Okayama,700-0824,34.6617,133.9350,,
16799232,16799487,JP,36,Matsue,690-0887,35.4722,133.0506,,
16799488,16799743,JP,45,Hofu,747-0801,34.0500,131.5667,,
You need to convert the IPs in your CSV to ints before creating the database. There's a function in ipinfo.py that will do that for you:
In [1]: import ipinfo
In [2]: ipinfo.ip2int('1.0.0.0')
Out[2]: 16777216
Perfect! I changed a couple of things in the cv2dat.py using ipinfo.ip2int as you mentioned, and it has worked properly!!!
Thanks a lot Mark! Excellent job!
No problem, glad it was useful to you!
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/admin/PycharmProjects/geoip/csv2dat.py -w GeoIPCity.dat mmorg GeoIPCity.csv Traceback (most recent call last): File "/Users/admin/PycharmProjects/geoip/csv2dat.py", line 475, in
rval = main()
File "/Users/admin/PycharmProjects/geoip/csv2dat.py", line 471, in main
return cmd(opts, args)
File "/Users/admin/PycharmProjects/geoip/csv2dat.py", line 439, in build_dat
r.load(opts, args)
File "/Users/admin/PycharmProjects/geoip/csv2dat.py", line 194, in load
for nets, data in self.gen_nets(opts, args):
File "/Users/admin/PycharmProjects/geoip/csv2dat.py", line 261, in gen_nets
for lo, hi, asn in gen_csv(fileinput.input(args)):
ValueError: too many values to unpack