ipdb

package
v0.0.0-...-6321830 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 6 Imported by: 0

README

IPIP-IPDB ip database seeker

Notes

  1. thread safe implementation
  2. no cache (cache to be managed by yourself)

Example

package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net"

	"github.com/OpenIPDB/geoip-seeker/ipdb"
)

func main() {
	data, _ := ioutil.ReadFile("testdata/ipiptest.ipdb")
	seeker, _ := ipdb.New(data)

	record, _ := seeker.LookupByIP(net.ParseIP("114.114.114.114"))

	encodedRecord, _ := json.MarshalIndent(record, "", "  ")

	fmt.Println(seeker.String())
	// IPIP(IPDB) 2018-08-31 385083 [IPv4]
	fmt.Println(seeker.RecordCount())
	// 385083
	fmt.Println(seeker.BuildTime())
	// 2018-08-31 00:00:00 +0800 CST
	fmt.Println(string(encodedRecord))
	// {
	//   "IP": "114.114.114.114",
	//   "CountryName": "114DNS.COM",
	//   "RegionName": "114DNS.COM"
	// }
}

Benchmark

$ go test --bench .
goos: darwin
goarch: amd64
pkg: github.com/OpenIPDB/geoip-seeker/ipdb
BenchmarkIPSeeker_LookupByIP-12    	 3452234	       354 ns/op
PASS
ok  	github.com/OpenIPDB/geoip-seeker/ipdb	2.952s

References

  1. https://ipip.net
  2. https://github.com/larryli/ipv4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Seeker

type Seeker struct {
	// contains filtered or unexported fields
}

func New

func New(data []byte) (*Seeker, error)

func (*Seeker) BuildTime

func (s *Seeker) BuildTime() time.Time

func (*Seeker) IPv4Support

func (s *Seeker) IPv4Support() bool

func (*Seeker) IPv6Support

func (s *Seeker) IPv6Support() bool

func (*Seeker) LanguageCode

func (s *Seeker) LanguageCode(code string) (err error)

func (*Seeker) LanguageNames

func (s *Seeker) LanguageNames() (names []string)

func (*Seeker) LookupByIP

func (s *Seeker) LookupByIP(address net.IP) (record *Record, err error)

func (*Seeker) RecordCount

func (s *Seeker) RecordCount() uint64

func (*Seeker) String

func (s *Seeker) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL