diff options
Diffstat (limited to 'plugin/maxmind')
| -rw-r--r-- | plugin/maxmind/common_out.go | 24 | ||||
| -rw-r--r-- | plugin/maxmind/maxmind_country_mmdb_in.go | 6 | ||||
| -rw-r--r-- | plugin/maxmind/maxmind_country_mmdb_out.go | 25 |
3 files changed, 29 insertions, 26 deletions
diff --git a/plugin/maxmind/common_out.go b/plugin/maxmind/common_out.go index bfd41aaa..01f10fc0 100644 --- a/plugin/maxmind/common_out.go +++ b/plugin/maxmind/common_out.go @@ -20,6 +20,17 @@ var ( defaultIPInfoOutputDir = filepath.Join("./", "output", "ipinfo") ) +// Reference: https://ipinfo.io/lite +type ipInfoLite struct { + ASN string `maxminddb:"asn"` + ASName string `maxminddb:"as_name"` + ASDomain string `maxminddb:"as_domain"` + Continent string `maxminddb:"continent"` + ContinentCode string `maxminddb:"continent_code"` + Country string `maxminddb:"country"` + CountryCode string `maxminddb:"country_code"` +} + func newGeoLite2CountryMMDBOut(iType string, iDesc string, action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { var tmp struct { OutputName string `json:"outputName"` @@ -144,19 +155,16 @@ func (g *GeoLite2CountryMMDBOut) GetExtraInfo() (map[string]any, error) { } case TypeIPInfoCountryMMDBOut: - record := struct { - Continent string `maxminddb:"continent"` - ContinentName string `maxminddb:"continent_name"` - Country string `maxminddb:"country"` - CountryName string `maxminddb:"country_name"` - }{} - + var record ipInfoLite _, err := networks.Network(&record) if err != nil { return nil, err } - countryCode := strings.ToUpper(strings.TrimSpace(record.Country)) + countryCode := strings.ToUpper(strings.TrimSpace(record.CountryCode)) if _, found := infoList[countryCode]; !found { + record.ASN = "" + record.ASName = "" + record.ASDomain = "" infoList[countryCode] = record } diff --git a/plugin/maxmind/maxmind_country_mmdb_in.go b/plugin/maxmind/maxmind_country_mmdb_in.go index 7578ba23..ab8be53f 100644 --- a/plugin/maxmind/maxmind_country_mmdb_in.go +++ b/plugin/maxmind/maxmind_country_mmdb_in.go @@ -127,14 +127,12 @@ func (g *GeoLite2CountryMMDBIn) generateEntries(content []byte, entries map[stri } case TypeIPInfoCountryMMDBIn: - record := struct { - Country string `maxminddb:"country"` - }{} + var record ipInfoLite subnet, err = networks.Network(&record) if err != nil { return err } - name = strings.ToUpper(strings.TrimSpace(record.Country)) + name = strings.ToUpper(strings.TrimSpace(record.CountryCode)) default: return lib.ErrNotSupportedFormat diff --git a/plugin/maxmind/maxmind_country_mmdb_out.go b/plugin/maxmind/maxmind_country_mmdb_out.go index cca77632..7cba249e 100644 --- a/plugin/maxmind/maxmind_country_mmdb_out.go +++ b/plugin/maxmind/maxmind_country_mmdb_out.go @@ -70,8 +70,8 @@ func (g *GeoLite2CountryMMDBOut) Output(container lib.Container) error { dbDesc = "Customized DB-IP Country Lite database" case TypeIPInfoCountryMMDBOut: - dbName = "IPInfo-Country" - dbDesc = "Customized IPInfo Country database" + dbName = "IPInfo-Lite" + dbDesc = "Customized IPInfo Lite database" recordSize = 32 } @@ -199,7 +199,7 @@ func (g *GeoLite2CountryMMDBOut) marshalData(writer *mmdbwriter.Tree, entry *lib case TypeIPInfoCountryMMDBOut: record = mmdbtype.Map{ - "country": mmdbtype.String(entry.GetName()), + "country_code": mmdbtype.String(entry.GetName()), } default: @@ -339,25 +339,22 @@ func (g *GeoLite2CountryMMDBOut) marshalData(writer *mmdbwriter.Tree, entry *lib } case TypeIPInfoCountryMMDBOut: - info, found := extraInfo[entry.GetName()].(struct { - Continent string `maxminddb:"continent"` - ContinentName string `maxminddb:"continent_name"` - Country string `maxminddb:"country"` - CountryName string `maxminddb:"country_name"` - }) - + info, found := extraInfo[entry.GetName()].(ipInfoLite) if !found { log.Printf("⚠️ [type %s | action %s] not found extra info for list %s\n", g.Type, g.Action, entry.GetName()) record = mmdbtype.Map{ - "country": mmdbtype.String(entry.GetName()), + "country_code": mmdbtype.String(entry.GetName()), } } else { record = mmdbtype.Map{ + "as_domain": mmdbtype.String(info.ASDomain), + "as_name": mmdbtype.String(info.ASName), + "asn": mmdbtype.String(info.ASN), "continent": mmdbtype.String(info.Continent), - "continent_name": mmdbtype.String(info.ContinentName), - "country": mmdbtype.String(entry.GetName()), - "country_name": mmdbtype.String(info.CountryName), + "continent_code": mmdbtype.String(info.ContinentCode), + "country": mmdbtype.String(info.Country), + "country_code": mmdbtype.String(entry.GetName()), } } |
