IP库阶段性提交(未完成)

This commit is contained in:
刘祥超
2022-08-14 19:42:05 +08:00
parent debf4a5249
commit ec02d83ee6
15 changed files with 5117 additions and 3512 deletions

View File

@@ -3,7 +3,9 @@
package iplibrary_test
import (
"encoding/json"
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
"github.com/iwind/TeaGo/maps"
"net"
"testing"
)
@@ -18,18 +20,29 @@ func TestNewFileReader(t *testing.T) {
"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())
var data = maps.Map{
"countryId": result.CountryId(),
"countryName": result.CountryName(),
"provinceId": result.ProvinceId(),
"provinceName": result.ProvinceName(),
"cityId": result.CityId(),
"cityName": result.CityName(),
"townId": result.TownId(),
"townName": result.TownName(),
"providerId": result.ProviderId(),
"providerName": result.ProviderName(),
}
dataJSON, err := json.MarshalIndent(data, "", " ")
if err != nil {
t.Fatal(err)
}
t.Log(ip, "=>", string(dataJSON))
} else {
t.Log(ip+":", "not found")
}