Comments (5)
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?
from mmutils.
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
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 321, in gen_nets
lo, hi = ipaddr.IPAddress(int(lo)), ipaddr.IPAddress(int(hi))
ValueError: invalid literal for int() with base 10: '1.0.0.0'
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,,
from mmutils.
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
from mmutils.
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!
from mmutils.
No problem, glad it was useful to you!
from mmutils.
Related Issues (14)
- hi, do you have dat to csv convert script HOT 1
- Except: Duplicate IPs HOT 1
- what would be required to support a few more databases? HOT 6
- csv2dat.py lhs tuple error - how to debug where the fault is? HOT 2
- license undefined HOT 2
- Did not work for GeoIP2 HOT 2
- any chance of your script supporting the new MMDB format? HOT 1
- How can I specify the encoding? HOT 1
- How can I fix this error? HOT 1
- Proper package structure
- AttributeError: 'module' object has no attribute 'ASNUM_EDITION_V6' HOT 1
- ValueError: need more than 0 values to unpack
- Wrong values after build .dat
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mmutils.