IP库增加多个辅助查询函数

This commit is contained in:
刘祥超
2023-08-24 12:21:26 +08:00
parent 6a42827ebd
commit f056a9c5bd
3 changed files with 74 additions and 0 deletions

View File

@@ -86,6 +86,41 @@ func TestIPLibrary_LookupIP(t *testing.T) {
}
}
func TestIPLibrary_LookupIP_Summary(t *testing.T) {
var lib = iplibrary.NewIPLibrary()
err := lib.InitFromData(iplibrary.DefaultIPLibraryData(), "")
if err != nil {
t.Fatal(err)
}
for _, ip := range []string{
"66.249.66.69",
"123456", // wrong ip
"", // empty
} {
var result = lib.LookupIP(ip)
if result.IsOk() {
t.Log(ip, "=>", "region summary:", result.RegionSummary(), "summary:", result.Summary())
} else {
t.Log(ip, "=>", "region summary:", result.RegionSummary(), "summary:", result.Summary())
}
}
}
func TestIPLibrary_LookupIPSummaries(t *testing.T) {
_ = iplibrary.InitDefault()
t.Logf("%+v", iplibrary.LookupIPSummaries([]string{
"127.0.0.1",
"8.8.8.8",
"4.4.4.4",
"202.96.0.20",
"111.197.165.199",
"66.249.66.69",
"2222", // wrong ip
"2406:8c00:0:3401:133:18:168:70", // ipv6
}))
}
func BenchmarkIPLibrary_Lookup(b *testing.B) {
var lib = iplibrary.NewIPLibrary()
err := lib.InitFromData(iplibrary.DefaultIPLibraryData(), "")