ip_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package ip
  2. import "testing"
  3. func TestIp(t *testing.T) {
  4. l, _ := New("./iprepo.txt")
  5. l, _ = New("./ip_test.txt")
  6. ips := []string{"000.000.000.001", "127.000.11.57", "183.131.11.57", "255.255.255.255", "3FFF:FFFF:FFFF:FEFF:FFFF:FFFF:FFFF:FFFF", "255.255.255", "0:0:0:0:0:0:0:1"}
  7. for _, ip := range ips {
  8. info := l.IP(ip)
  9. t.Log(info)
  10. zone := l.Zone(ip)
  11. t.Log(zone)
  12. }
  13. // Zone
  14. zone := l.Zone("")
  15. t.Log(zone)
  16. zone = l.Zone("0:0:0:0:0:0:0:1")
  17. t.Log(zone)
  18. // All
  19. infos := l.All()
  20. t.Log(infos)
  21. InternalIP()
  22. // InetAtoN
  23. InetAtoN("183.131.11.57")
  24. InetAtoN("183.131.11")
  25. InetAtoN("0:0:0:0:0:0:0:1")
  26. // InetNtoA
  27. InetNtoA(84549632)
  28. // ZoneID
  29. ZoneID("中国", "福建", "莆田")
  30. }
  31. func TestExternalIP(t *testing.T) {
  32. t.Log(ExternalIP())
  33. }
  34. func BenchmarkIP(b *testing.B) {
  35. l, _ := New("./iprepo.txt")
  36. b.ResetTimer()
  37. b.RunParallel(func(pb *testing.PB) {
  38. for pb.Next() {
  39. l.IP("183.131.11.57")
  40. }
  41. })
  42. }
  43. func BenchmarkZone(b *testing.B) {
  44. l, _ := New("./iprepo.txt")
  45. b.ResetTimer()
  46. b.RunParallel(func(pb *testing.PB) {
  47. for pb.Next() {
  48. l.Zone("183.131.11.57")
  49. }
  50. })
  51. }