ip2region_v2

package
v1.0.173 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderInfoLength      = 256
	VectorIndexRows       = 256
	VectorIndexCols       = 256
	VectorIndexSize       = 8
	SegmentIndexBlockSize = 14
)

Variables

This section is empty.

Functions

func CheckIP

func CheckIP(ip string) (uint32, error)

func LoadContent

func LoadContent(handle *os.File) ([]byte, error)

LoadContent load the whole xdb content from the specified file handle

func LoadContentFromFile

func LoadContentFromFile(dbFile string) ([]byte, error)

LoadContentFromFile load the whole xdb content from the specified db file path

func LoadVectorIndex

func LoadVectorIndex(handle *os.File) ([]byte, error)

LoadVectorIndex util function to load the vector index from the specified file handle

func LoadVectorIndexFromFile

func LoadVectorIndexFromFile(dbFile string) ([]byte, error)

LoadVectorIndexFromFile load vector index from a specified file path

func Long2IP

func Long2IP(ip uint32) string

func MidIP

func MidIP(sip uint32, eip uint32) uint32

func OnlineDownload

func OnlineDownload()

Types

type Client

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

func New

func New(filepath string) (*Client, error)

func NewBuff added in v1.0.161

func NewBuff(file []byte) (*Client, error)

func (*Client) Query

func (c *Client) Query(ipAddress net.IP) (result QueryResult, err error)

func (*Client) QueryIP added in v1.0.161

func (c *Client) QueryIP(ipAddressStr string) (result QueryResult, err error)

QueryIP ip地址查询对应归属地信息

type Header struct {
	// data []byte
	Version       uint16
	IndexPolicy   IndexPolicy
	CreatedAt     uint32
	StartIndexPtr uint32
	EndIndexPtr   uint32
}

func LoadHeader

func LoadHeader(handle *os.File) (*Header, error)

LoadHeader load the header info from the specified handle

func LoadHeaderFromBuff

func LoadHeaderFromBuff(cBuff []byte) (*Header, error)

LoadHeaderFromBuff wrap the header info from the content buffer

func LoadHeaderFromFile

func LoadHeaderFromFile(dbFile string) (*Header, error)

LoadHeaderFromFile load header info from the specified db file path

func NewHeader

func NewHeader(input []byte) (*Header, error)

type IndexPolicy

type IndexPolicy int
const (
	VectorIndexPolicy IndexPolicy = 1
	BTreeIndexPolicy  IndexPolicy = 2
)

func (IndexPolicy) String

func (i IndexPolicy) String() string

type QueryResult

type QueryResult struct {
	Ip       string `json:"ip,omitempty"`       // ip
	Country  string `json:"country,omitempty"`  // 国家
	Province string `json:"province,omitempty"` // 省份
	City     string `json:"city,omitempty"`     // 城市
	Operator string `json:"operator,omitempty"` // 运营商
}

QueryResult 返回

type Searcher

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

func NewWithBuffer

func NewWithBuffer(cBuff []byte) (*Searcher, error)

func NewWithFileOnly

func NewWithFileOnly(dbFile string) (*Searcher, error)

func NewWithVectorIndex

func NewWithVectorIndex(dbFile string, vIndex []byte) (*Searcher, error)

func (*Searcher) Close

func (s *Searcher) Close()

func (*Searcher) GetIOCount

func (s *Searcher) GetIOCount() int

GetIOCount return the global io count for the last search

func (*Searcher) Search

func (s *Searcher) Search(ip uint32) (string, error)

Search find the region for the specified long ip

func (*Searcher) SearchByStr

func (s *Searcher) SearchByStr(str string) (string, error)

SearchByStr find the region for the specified ip string

Jump to

Keyboard shortcuts

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