ipGeo

package module
v0.0.0-...-180661b Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2022 License: MIT Imports: 10 Imported by: 0

README

ipGeo

用于查询IP地理信息的GO库,同时支持IPv4和IPv6,使用纯真IPv4数据库和zxinc数据库,提供查询和下载功能,不产生多余依赖和输出。

使用

引入ipGeo
import "github.com/HSwift/ipGeo"
下载数据库
ipGeo.DownloadIPv4DB("./ipv4.db") # ipv4数据库
ipGeo.DownloadIPv6DB("./ipv6.db") # IPv6数据库
查询IP地址

IPv4

ipdb,_ := ipGeo.OpenIPv4DB("./ipv4.db")
res,_ := ipdb.GetIPLocation("1.1.1.1")
println(res.Country,res.Area)

IPv6

ipdb,_ := ipGeo.OpenIPv6DB("./ipv6.db")
res,_ := ipdb.GetIPLocation("2400::1")
println(res.Country,res.Area)
完整实例

参考 main.go

注意

数据库格式错误会产生未定义的错误。

感谢

纯真IP数据库 提供的IPv4数据

zxinc数据库 提供的IPv6数据

https://github.com/zu1k/nali

https://github.com/freshcn/qqwry

https://gist.github.com/rmb122/ec7f305679ae9921a79b571d56390a74

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadIPv4DB

func DownloadIPv4DB(path string) error

func DownloadIPv6DB

func DownloadIPv6DB(path string) error

Types

type IPDB

type IPDB interface {
	GetIPLocation(string) (*Result, error)
	GetIPNumLocation(net.IP) (*Result, error)
}

type IPv4DB

type IPv4DB struct {
	IndexStart   uint32
	RecordsCount uint32
	// contains filtered or unexported fields
}

func OpenIPv4DB

func OpenIPv4DB(path string) (*IPv4DB, error)

func (*IPv4DB) GetIPLocation

func (db *IPv4DB) GetIPLocation(ip string) (*Result, error)

func (*IPv4DB) GetIPNumLocation

func (db *IPv4DB) GetIPNumLocation(ipBytes net.IP) (*Result, error)

type IPv6DB

type IPv6DB struct {
	IndexStart   uint64
	RecordsCount uint64
	// contains filtered or unexported fields
}

func OpenIPv6DB

func OpenIPv6DB(path string) (*IPv6DB, error)

func (*IPv6DB) GetIPLocation

func (db *IPv6DB) GetIPLocation(ip string) (*Result, error)

func (*IPv6DB) GetIPNumLocation

func (db *IPv6DB) GetIPNumLocation(ipBytes net.IP) (*Result, error)

type Result

type Result struct {
	IP      net.IP
	Country string
	Area    string
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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