Comments (4)
from mmdb-from-go-blogpost.
Hi, I think you're probably running into an issue with the private IP range. If you set the IncludeReservedNetworks
option to true
, it should work.
Here is some sample code to do what you've asked:
package main
import (
"log"
"net"
"os"
"github.com/maxmind/mmdbwriter"
"github.com/maxmind/mmdbwriter/inserter"
"github.com/maxmind/mmdbwriter/mmdbtype"
)
func main() {
// Load the database we wish to enrich.
writer, err := mmdbwriter.Load("GeoLite2-City.mmdb", mmdbwriter.Options{IncludeReservedNetworks: true})
if err != nil {
log.Fatal(err)
}
// Define and insert the new data.
data := mmdbtype.Map{
"country": mmdbtype.Map{
"geoname_id": mmdbtype.Uint32(1880251),
"iso_code": mmdbtype.String("SG"),
"names": mmdbtype.Map{
"en": mmdbtype.String("Singapore"),
},
},
}
_, network1, err := net.ParseCIDR("10.200.11.0/28")
if err != nil {
log.Fatal(err)
}
if err := writer.InsertFunc(network1, inserter.TopLevelMergeWith(data)); err != nil {
log.Fatal(err)
}
_, network2, err := net.ParseCIDR("10.200.11.16/30")
if err != nil {
log.Fatal(err)
}
if err := writer.InsertFunc(network2, inserter.TopLevelMergeWith(data)); err != nil {
log.Fatal(err)
}
_, network3, err := net.ParseCIDR("10.200.11.20/32")
if err != nil {
log.Fatal(err)
}
if err := writer.InsertFunc(network3, inserter.TopLevelMergeWith(data)); err != nil {
log.Fatal(err)
}
// Write the newly enriched DB to the filesystem.
fh, err := os.Create("GeoLite2-City-with-Reserved-SG-Data.mmdb")
if err != nil {
log.Fatal(err)
}
_, err = writer.WriteTo(fh)
if err != nil {
log.Fatal(err)
}
}
I adapted the example from the blogpost, switching to GeoLite2-City.mmdb, changing the data we use to the data you supplied, using a CIDR calculator to determine the ranges for 10.200.11.0 - 10.200.11.20, and using the IncludeReservedNetworks
as discussed above.
from mmdb-from-go-blogpost.
from mmdb-from-go-blogpost.
Hi Nanaji, glad it worked out for you. The source database was originally generated by https://github.com/maxmind/MaxMind-DB-Reader-perl and the implementation is slightly different than using this library. It is safe to ignore the difference in file size, as it is an implementation detail. Databases generated with this library will be slightly smaller than those generated with the Perl one, generally, due to a difference in the logic on when to use a pointer.
from mmdb-from-go-blogpost.
Related Issues (11)
- github.com/oschwald/[email protected]: invalid version: HOT 1
- How to insert custom region data with ipaddr HOT 1
- How to remove one or more columns HOT 1
- how can i just insert an ip with some related datas, rather than insert ip range? HOT 1
- license information is missing HOT 1
- Incorrect result after import from CSV file HOT 1
- One Node dissapeared after Inserting data HOT 3
- Splunk can't load the updated mmdb file HOT 5
- show custom geoip fields HOT 12
- Custom DB with Logstash GeoIP filter HOT 3
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 mmdb-from-go-blogpost.