All Projects → kayon → iploc

kayon / iploc

Licence: BSD-3-Clause license
每秒百万高性能IP查询库,使用纯真IP库,国内省、市、县,qqwry.dat转换工具:GBK转为UTF-8

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to iploc

Netlink
Socket and Networking Library using msgpack.org[C++11]
Stars: ✭ 197 (+258.18%)
Mutual labels:  utf-8
QQWry
Delphi interface for QQWry IP database
Stars: ✭ 14 (-74.55%)
Mutual labels:  qqwry
lexer
Hackable Lexer with UTF-8 support
Stars: ✭ 19 (-65.45%)
Mutual labels:  utf-8
Stringy
A PHP string manipulation library with multibyte support
Stars: ✭ 2,461 (+4374.55%)
Mutual labels:  utf-8
utf utils
My work on high-speed conversion of UTF-8 to UTF-32/UTF-16
Stars: ✭ 45 (-18.18%)
Mutual labels:  utf-8
utf8-validator
UTF-8 Validator
Stars: ✭ 18 (-67.27%)
Mutual labels:  utf-8
Encoding
Encoding Standard
Stars: ✭ 176 (+220%)
Mutual labels:  utf-8
ubase
remove accents from utf8 strings
Stars: ✭ 14 (-74.55%)
Mutual labels:  utf-8
S51 UTF 8 FontLibrary
UTF-8 font dot matrix data is saved through external FLASH
Stars: ✭ 30 (-45.45%)
Mutual labels:  utf-8
characteristics
Character info under different encodings
Stars: ✭ 25 (-54.55%)
Mutual labels:  utf-8
ShellAnything
ShellAnything is a C++ open-source software which allow one to easily customize and add new options to *Windows Explorer* context menu. Define specific actions when a user right-click on a file or a directory.
Stars: ✭ 103 (+87.27%)
Mutual labels:  utf-8
ocreval
Update of the ISRI Analytic Tools for OCR Evaluation with UTF-8 support
Stars: ✭ 48 (-12.73%)
Mutual labels:  utf-8
enc
A simple class for storing UTF-8 strings
Stars: ✭ 12 (-78.18%)
Mutual labels:  utf-8
Str
A fast, solid and strong typed string manipulation library with multibyte support
Stars: ✭ 199 (+261.82%)
Mutual labels:  utf-8
fast-text-encoding
Fast polyfill for TextEncoder and TextDecoder, only supports UTF-8
Stars: ✭ 78 (+41.82%)
Mutual labels:  utf-8
Stringz
💯 Super fast unicode-aware string manipulation Javascript library
Stars: ✭ 181 (+229.09%)
Mutual labels:  utf-8
qqwry.dat
纯真IP地址数据库镜像,mirror of qqwry.dat
Stars: ✭ 359 (+552.73%)
Mutual labels:  qqwry
string theory
Flexible modern C++ string library with type-safe formatting
Stars: ✭ 32 (-41.82%)
Mutual labels:  utf-8
simdutf8
SIMD-accelerated UTF-8 validation for Rust.
Stars: ✭ 426 (+674.55%)
Mutual labels:  utf-8
homoglyphs
Homoglyphs: get similar letters, convert to ASCII, detect possible languages and UTF-8 group.
Stars: ✭ 70 (+27.27%)
Mutual labels:  utf-8

iploc

Build Status

使用纯真IP库 qqwry.dat,高性能,线程安全,并对国内数据格式化到省、市、县

需要 go 1.9 或更高

附带的 qqwry.datUTF-8 编码 2018-05-15版本

不再提供 qqwry.dat, 新增命令行工具 iploc-fetch, 可在线获取官方最新版本的 qqwry.dat

安装

go get -u github.com/kayon/iploc/...

无法安装 golang.org/x/text 包,没有梯子使用下面方法

$ mkdir -P $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/text.git

获取&更新 qqwry.dat

1. 下载 qqwry.dat

方法一:使用命令行工具 iploc-fetch

由于服务器限制国外IP,只能使用国内网络。

下载到当前目录,保存为 qqwry.gbk.dat

$ iploc-fetch qqwry.gbk.dat
方法二:手动下载

纯真官网下载并安装,复制安装目录中的 qqwry.dat

2. 转换为 UTF-8

使用命令行工具 iploc-conv 将刚刚下载的 qqwry.gbk.dat 转换为 UTF-8 保存为 qqwry.dat

iploc-conv -s qqwry.gbk.dat -d qqwry.dat

Benchmarks

// 缓存索引
BenchmarkFind-8            	 2000000	       735 ns/op               136万/秒
// 无索引
BenchmarkFindUnIndexed-8   	   20000	     78221 ns/op               1.2万/秒
// 缓存索引,并发
BenchmarkFindParallel-8    	10000000	       205 ns/op               487万/秒

使用

func main() {
	loc, err := iploc.Open("qqwry.dat")
	if err != nil {
		panic(err)
	}
	detail := loc.Find("8.8.8") // 补全为8.8.0.8, 参考 ping 工具
	fmt.Printf("IP:%s; 网段:%s - %s; %s\n", detail.IP, detail.Start, detail.End, detail)
	
	detail2 := loc.Find("8.8.3.1")
	fmt.Printf("%t %t\n", detail.In(detail2.IP.String()), detail.String() == detail2.String())

	// output
	// IP:8.8.0.8; 网段: 8.7.245.0 - 8.8.3.255; 美国 科罗拉多州布隆菲尔德市Level 3通信股份有限公司
	// true true
	
	detail = loc.Find("1.24.41.0")
	fmt.Println(detail.String())
	fmt.Println(detail.Country, detail.Province, detail.City, detail.County)
	
	// output
	// 内蒙古锡林郭勒盟苏尼特右旗 联通
	// 中国 内蒙古 锡林郭勒盟 苏尼特右旗
	
}	

快捷方法

Find(qqwrySrc, ip string) (*Detail, error)

iploc.Find 使用 OpenWithoutIndexes

初始化

Open(qqwrySrc string) (*Locator, error)

iploc.Open 缓存并索引,生成索引需要耗时500毫秒左右,但会带来更高的查询性能

OpenWithoutIndexes(qqwrySrc string) (*Locator, error)

iploc.OpenWithoutIndexes 只读取文件头做简单检查,无索引

查询

(*Locator).Find(ip string) *Detail

如果IP不合法,返回 nil

命令行工具

iploc-conv

将原版 qqwry.datGBK 转换为 UTF-8

$ iploc-conv -s src.gbk.dat -d dst.utf8.dat

新生成的DAT文件保留原数据结构,由于编码原因,文件会增大一点

修正原 qqwry.dat 中几处错误的重定向 (qqwry.dat 2018-05-10),并将 "CZ88.NET" 替换为 "N/A"

iploc-fetch

从纯真官网下载最新 qqwry.dat

由于服务器限制国外IP,只能使用国内网络。

$ iploc-fetch qqwry.gbk.dat

下载后别忘了使用 iploc-conv 转换为 UTF-8

iploc-gen

创建静态版本的 iploc 集成到你的项目中

iploc-gen 会在当前目录创建 iploc-binary.go 文件,拷贝到你的项目中,通过变量名 IPLoc 直接可以使用

$ iploc-gen path/qqwry.dat

--pkg 指定 package name, 默认 main

-n 使用 OpenWithoutIndexes 初始化,无索引

静态编译 iploc 和 qqwry.dat 并集成到你的项目中

编译后的二进制没有 qqwry.dat 依赖,不需要再带着 qqwry.dat 一起打包了

示例

到项目目录 $GOPATH/src/myproject/

$ mkdir myloc && cd myloc
$ iploc-gen path/qqwry.dat --pkg myloc

$GOPATH/src/myproject/main.go

package main
	
import (
	"fmt"
	
	"myproject/myloc"
)
	
func main() {
	fmt.Println(myloc.IPLoc.Find("8.8.8.8"))
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].