forked from samwafgo/SamWaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_test.go
33 lines (31 loc) · 997 Bytes
/
common_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package utils
import (
"fmt"
"github.com/oschwald/geoip2-golang"
"log"
"net"
"testing"
)
func TestIPv6(t *testing.T) {
db, err := geoip2.Open("../data/ipv6/GeoLite2-Country.mmdb")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// If you are using strings that may be invalid, check that ip is not nil
ip := net.ParseIP("2409:8087:3c02:21:0:1:0:100a")
record, err := db.City(ip)
if err != nil {
log.Fatal(err)
}
fmt.Printf("国家: %v\n", record.Country.Names["zh-CN"])
fmt.Sprintf("%v", record)
fmt.Printf("Portuguese (BR) city name: %v\n", record.City.Names["pt-BR"])
if len(record.Subdivisions) > 0 {
fmt.Printf("English subdivision name: %v\n", record.Subdivisions[0].Names["en"])
}
fmt.Printf("Russian country name: %v\n", record.Country.Names["ru"])
fmt.Printf("ISO country code: %v\n", record.Country.IsoCode)
fmt.Printf("Time zone: %v\n", record.Location.TimeZone)
fmt.Printf("Coordinates: %v, %v\n", record.Location.Latitude, record.Location.Longitude)
}