-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thiago Tognoli
committed
Oct 30, 2024
1 parent
b9ab8c6
commit 8953bca
Showing
51 changed files
with
2,450 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Aleksey Lin <[email protected]> (https://incsw.in) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
[Forked from](https://github.com/IncSW/geoip2) to support yaegi with new features | ||
|
||
[](LICENSE) | ||
[](https://goreportcard.com/report/github.com/IncSW/geoip2) | ||
[](https://pkg.go.dev/github.com/IncSW/geoip2?tab=doc) | ||
|
||
# GeoIP2 Reader for Go | ||
|
||
This library reads MaxMind GeoIP2 databases. | ||
|
||
Inspired by [oschwald/geoip2-golang](https://github.com/oschwald/geoip2-golang). | ||
|
||
## Installation | ||
|
||
`go get github.com/IncSW/geoip2` | ||
|
||
## Quick Start | ||
|
||
```go | ||
import "github.com/IncSW/geoip2" | ||
|
||
reader, err := geoip2.NewCityReaderFromFile("path/to/GeoIP2-City.mmdb") | ||
if err != nil { | ||
panic(err) | ||
} | ||
record, err := reader.Lookup(net.ParseIP("81.2.69.142")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
println(record.Continent.Names["zh-CN"]) // 欧洲 | ||
println(record.City.Names["pt-BR"]) // Wimbledon | ||
if len(record.Subdivisions) != 0 { | ||
println(record.Subdivisions[0].Names["en"]) // England | ||
} | ||
println(record.Country.Names["ru"]) // Великобритания | ||
println(record.Country.ISOCode) // GB | ||
println(record.Location.TimeZone) // Europe/London | ||
println(record.Country.GeoNameID) // 2635167, https://www.geonames.org/2635167 | ||
``` | ||
|
||
## Performance | ||
|
||
### [IncSW/geoip2](https://github.com/IncSW/geoip2) | ||
``` | ||
city-24 342847 2981 ns/op 2032 B/op 12 allocs/op | ||
city_parallel-24 4477626 269 ns/op 2032 B/op 12 allocs/op | ||
isp-24 3539738 336 ns/op 64 B/op 1 allocs/op | ||
isp_parallel-24 46938070 25.7 ns/op 64 B/op 1 allocs/op | ||
connection_type-24 8759110 133 ns/op 0 B/op 0 allocs/op | ||
connection_type_parallel-24 142261742 8.34 ns/op 0 B/op 0 allocs/op | ||
``` | ||
|
||
### [oschwald/geoip2-golang](https://github.com/oschwald/geoip2-golang) | ||
``` | ||
city-24 109092 10717 ns/op 2848 B/op 103 allocs/op | ||
city_parallel-24 662510 1718 ns/op 2848 B/op 103 allocs/op | ||
isp-24 1688287 705 ns/op 112 B/op 4 allocs/op | ||
isp_parallel-24 14285560 84.4 ns/op 112 B/op 4 allocs/op | ||
connection_type-24 3883234 305 ns/op 32 B/op 2 allocs/op | ||
connection_type_parallel-24 34284831 32.1 ns/op 32 B/op 2 allocs/op | ||
``` | ||
|
||
## Supported databases types | ||
|
||
### Country | ||
- GeoIP2-Country | ||
- GeoLite2-Country | ||
- DBIP-Country | ||
- DBIP-Country-Lite | ||
|
||
### City | ||
- GeoIP2-City | ||
- GeoLite2-City | ||
- GeoIP2-Enterprise | ||
- DBIP-City-Lite | ||
|
||
### ISP | ||
- GeoIP2-ISP | ||
|
||
### ASN | ||
- GeoLite2-ASN | ||
- DBIP-ASN-Lite | ||
- DBIP-ASN-Lite (compat=GeoLite2-ASN) | ||
|
||
### Connection Type | ||
- GeoIP2-Connection-Type | ||
|
||
### Anonymous IP | ||
- GeoIP2-Anonymous-IP | ||
|
||
### Domain | ||
- GeoIP2-Domain | ||
|
||
## License | ||
|
||
[MIT License](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package geoip2_iso88591 | ||
|
||
import "errors" | ||
|
||
func readAnonymousIPMap(result *AnonymousIP, buffer []byte, mapSize, offset uint) (uint, error) { | ||
var key []byte | ||
var err error | ||
for i := uint(0); i < mapSize; i++ { | ||
key, offset, err = readMapKey(buffer, offset) | ||
if err != nil { | ||
return 0, err | ||
} | ||
switch bytesToKeyString(key) { | ||
case "is_anonymous": | ||
result.IsAnonymous, offset, err = readBool(buffer, offset) | ||
if err != nil { | ||
return 0, err | ||
} | ||
case "is_anonymous_vpn": | ||
result.IsAnonymousVPN, offset, err = readBool(buffer, offset) | ||
if err != nil { | ||
return 0, err | ||
} | ||
case "is_hosting_provider": | ||
result.IsHostingProvider, offset, err = readBool(buffer, offset) | ||
if err != nil { | ||
return 0, err | ||
} | ||
case "is_public_proxy": | ||
result.IsPublicProxy, offset, err = readBool(buffer, offset) | ||
if err != nil { | ||
return 0, err | ||
} | ||
case "is_tor_exit_node": | ||
result.IsTorExitNode, offset, err = readBool(buffer, offset) | ||
if err != nil { | ||
return 0, err | ||
} | ||
case "is_residential_proxy": | ||
result.IsResidentialProxy, offset, err = readBool(buffer, offset) | ||
if err != nil { | ||
return 0, err | ||
} | ||
default: | ||
return 0, errors.New("unknown anonymous ip key: " + string(key)) | ||
} | ||
} | ||
return offset, nil | ||
} |
Oops, something went wrong.