mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-23 19:20:24 +08:00
新版IP库管理阶段性提交(未完成)
This commit is contained in:
37
pkg/iplibrary/reader_file_test.go
Normal file
37
pkg/iplibrary/reader_file_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package iplibrary_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewFileReader(t *testing.T) {
|
||||
reader, err := iplibrary.NewFileReader("./ip.db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, ip := range []string{
|
||||
"127.0.0.1",
|
||||
"192.168.0.1",
|
||||
"192.168.0.150",
|
||||
"192.168.1.100",
|
||||
"192.168.2.100",
|
||||
"192.168.3.50",
|
||||
"192.168.0.150",
|
||||
"192.168.4.80",
|
||||
"8.8.8.8",
|
||||
"111.197.165.199",
|
||||
"175.178.206.125",
|
||||
} {
|
||||
var result = reader.Lookup(net.ParseIP(ip))
|
||||
if result.IsOk() {
|
||||
t.Log(ip+":", "countryId:", result.CountryId(), "provinceId:", result.ProvinceId(), "cityId:", result.CityId(), "provider:", result.ProviderId())
|
||||
} else {
|
||||
t.Log(ip+":", "not found")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user