iplocate

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: MIT Imports: 6 Imported by: 0

README

ip归属地查询库(基于纯真ip库)

About

又一个基于纯真ip库的解析程序。初学Golang练手的作品。

Document

Installation

go get -u github.com/yzchan/iploc

Quickstart

package main

import (
	"fmt"
	iplocate "github.com/yzchan/iploc"
)

func main() {
	q, err := iplocate.NewQQWryParser("../data/qqwry.dat")
	if err != nil {
		panic(err)
	}
	textA, textB := q.Find("127.0.0.1")
	fmt.Println(textA, textB)
}

Benchmarks

go test -v -run="none" -bench=. -benchmem -benchtime=3s
// 测试环境 2017款13寸MBP 8GB(2133MHz)
goos: darwin
goarch: amd64
pkg: github.com/yzchan/ip-locate
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
BenchmarkFind
BenchmarkFind-4                  6399915               552.2 ns/op           568 B/op          6 allocs/op
BenchmarkFindParallel
BenchmarkFindParallel-4         12724434               335.8 ns/op           568 B/op          6 allocs/op
PASS
ok      github.com/yzchan/ip-locate     8.769s

Features

  • 纯真ip库的下载
  • 将格式化之后的数据缓存在内存中,以获得更高的查询性能。

Thinks

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QQWryParser

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

func NewQQWryParser

func NewQQWryParser(filepath string) (q *QQWryParser, err error)

func (*QQWryParser) Find

func (q *QQWryParser) Find(ipStr string) (recordA string, recordB string)

Find 查询函数

func (*QQWryParser) FormatMap

func (q *QQWryParser) FormatMap()

func (*QQWryParser) Version

func (q *QQWryParser) Version() string

Version 返回版本信息

type Record

type Record struct {
	RecordA string
	RecordB string
}

type Result

type Result struct {
	StartIP net.IP
	StopIP  net.IP
	Record
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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