Skip to content

Commit

Permalink
Make GetASN() return a netmask
Browse files Browse the repository at this point in the history
(this isn't actually used, I think, but the interface{} says
it should be returned...)
  • Loading branch information
abh committed Dec 28, 2019
1 parent 011d8cf commit 00c5936
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions targeting/geoip2/geoip2.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ func (g *GeoIP2) HasASN() (bool, error) {
return false, err return false, err
} }


// GetASN returns the ASN for the IP (as a "as123" string and // GetASN returns the ASN for the IP (as a "as123" string) and the netmask
// an integer)
func (g *GeoIP2) GetASN(ip net.IP) (string, int, error) { func (g *GeoIP2) GetASN(ip net.IP) (string, int, error) {
r, err := g.get(asnDB, "") r, err := g.get(asnDB, "")
log.Printf("GetASN for %s, got DB? %s", ip, err)
if err != nil { if err != nil {
return "", 0, err return "", 0, err
} }
Expand All @@ -158,7 +158,11 @@ func (g *GeoIP2) GetASN(ip net.IP) (string, int, error) {
return "", 0, fmt.Errorf("lookup ASN for '%s': %s", ip.String(), err) return "", 0, fmt.Errorf("lookup ASN for '%s': %s", ip.String(), err)
} }
asn := c.AutonomousSystemNumber asn := c.AutonomousSystemNumber
return fmt.Sprintf("as%d", asn), 0, nil netmask := 24
if ip.To4() != nil {
netmask = 48
}
return fmt.Sprintf("as%d", asn), netmask, nil
} }


// HasCountry checks if the GeoIP country database is available // HasCountry checks if the GeoIP country database is available
Expand Down

0 comments on commit 00c5936

Please sign in to comment.