mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-06 14:50:24 +08:00
IP库阶段性提交(未完成)
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user