Skip to content

Commit

Permalink
Add support for MCC/MNC data
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Jan 28, 2022
1 parent afabd69 commit d1573b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
6 changes: 5 additions & 1 deletion reader.go
Expand Up @@ -74,8 +74,10 @@ type Enterprise struct {
IsLegitimateProxy bool `maxminddb:"is_legitimate_proxy"`
IsSatelliteProvider bool `maxminddb:"is_satellite_provider"`
ISP string `maxminddb:"isp"`
StaticIPScore float64 `maxminddb:"static_ip_score"`
MobileCountryCode string `maxminddb:"mobile_country_code"`
MobileNetworkCode string `maxminddb:"mobile_network_code"`
Organization string `maxminddb:"organization"`
StaticIPScore float64 `maxminddb:"static_ip_score"`
UserType string `maxminddb:"user_type"`
} `maxminddb:"traits"`
}
Expand Down Expand Up @@ -198,6 +200,8 @@ type ISP struct {
AutonomousSystemNumber uint `maxminddb:"autonomous_system_number"`
AutonomousSystemOrganization string `maxminddb:"autonomous_system_organization"`
ISP string `maxminddb:"isp"`
MobileCountryCode string `maxminddb:"mobile_country_code"`
MobileNetworkCode string `maxminddb:"mobile_network_code"`
Organization string `maxminddb:"organization"`
}

Expand Down
22 changes: 17 additions & 5 deletions reader_test.go
Expand Up @@ -211,21 +211,33 @@ func TestEnterprise(t *testing.T) {
assert.Equal(t, "Cable/DSL", record.Traits.ConnectionType)
assert.Equal(t, "frpt.net", record.Traits.Domain)
assert.Equal(t, float64(0.34), record.Traits.StaticIPScore)

record, err = reader.Enterprise(net.ParseIP("149.101.100.0"))
require.NoError(t, err)

assert.Equal(t, uint(6167), record.Traits.AutonomousSystemNumber)

assert.Equal(t, "CELLCO-PART", record.Traits.AutonomousSystemOrganization)
assert.Equal(t, "Verizon Wireless", record.Traits.ISP)
assert.Equal(t, "310", record.Traits.MobileCountryCode)
assert.Equal(t, "004", record.Traits.MobileNetworkCode)
}

func TestISP(t *testing.T) {
reader, err := Open("test-data/test-data/GeoIP2-ISP-Test.mmdb")
assert.Nil(t, err)
defer reader.Close()

record, err := reader.ISP(net.ParseIP("1.128.0.0"))
record, err := reader.ISP(net.ParseIP("149.101.100.0"))
assert.Nil(t, err)

assert.Equal(t, uint(1221), record.AutonomousSystemNumber)
assert.Equal(t, uint(6167), record.AutonomousSystemNumber)

assert.Equal(t, "Telstra Pty Ltd", record.AutonomousSystemOrganization)
assert.Equal(t, "Telstra Internet", record.ISP)
assert.Equal(t, "Telstra Internet", record.Organization)
assert.Equal(t, "CELLCO-PART", record.AutonomousSystemOrganization)
assert.Equal(t, "Verizon Wireless", record.ISP)
assert.Equal(t, "310", record.MobileCountryCode)
assert.Equal(t, "004", record.MobileNetworkCode)
assert.Equal(t, "Verizon Wireless", record.Organization)
}

// This ensures the compiler does not optimize away the function call
Expand Down

0 comments on commit d1573b8

Please sign in to comment.