IPIP.net officially supported IP database ipdb format parsing library

Related tags

Network ipdb-go
Overview

ipdb-go

TravisCI Build Status Coverage Status IPDB Database API Document

IPIP.net officially supported IP database ipdb format parsing library

Installing

go get github.com/ipipdotnet/ipdb-go

Code Example

支持IPDB格式地级市精度IP离线库(免费版,每周高级版,每日标准版,每日高级版,每日专业版,每日旗舰版)


package main

import (
	"github.com/ipipdotnet/ipdb-go"
	"fmt"
	"log"
)

func main() {
	db, err := ipdb.NewCity("/path/to/city.ipv4.ipdb")
	if err != nil {
		log.Fatal(err)
	}

	db.Reload("/path/to/city.ipv4.ipdb") // 更新 ipdb 文件后可调用 Reload 方法重新加载内容

	fmt.Println(db.IsIPv4()) // check database support ip type
	fmt.Println(db.IsIPv6()) // check database support ip type
	fmt.Println(db.BuildTime()) // database build time
	fmt.Println(db.Languages()) // database support language
	fmt.Println(db.Fields()) // database support fields

	fmt.Println(db.FindInfo("2001:250:200::", "CN")) // return CityInfo
	fmt.Println(db.Find("1.1.1.1", "CN")) // return []string
	fmt.Println(db.FindMap("118.28.8.8", "CN")) // return map[string]string
	fmt.Println(db.FindInfo("127.0.0.1", "CN")) // return CityInfo

	fmt.Println()
}

地级市精度库数据字段说明

country_name : 国家名字 (每周高级版及其以上版本包含)
region_name  : 省名字   (每周高级版及其以上版本包含)
city_name    : 城市名字 (每周高级版及其以上版本包含)
owner_domain : 所有者   (每周高级版及其以上版本包含)
isp_domain  : 运营商 (每周高级版与每日高级版及其以上版本包含)
latitude  :  纬度   (每日标准版及其以上版本包含)
longitude : 经度    (每日标准版及其以上版本包含)
timezone : 时区     (每日标准版及其以上版本包含)
utc_offset : UTC时区    (每日标准版及其以上版本包含)
china_admin_code : 中国行政区划代码 (每日标准版及其以上版本包含)
idd_code : 国家电话号码前缀 (每日标准版及其以上版本包含)
country_code : 国家2位代码  (每日标准版及其以上版本包含)
continent_code : 大洲代码   (每日标准版及其以上版本包含)
idc : IDC |  VPN   (每日专业版及其以上版本包含)
base_station : 基站 | WIFI (每日专业版及其以上版本包含)
country_code3 : 国家3位代码 (每日专业版及其以上版本包含)
european_union : 是否为欧盟成员国: 1 | 0 (每日专业版及其以上版本包含)
currency_code : 当前国家货币代码    (每日旗舰版及其以上版本包含)
currency_name : 当前国家货币名称    (每日旗舰版及其以上版本包含)
anycast : ANYCAST       (每日旗舰版及其以上版本包含)

适用于IPDB格式的中国地区 IPv4 区县库

db, err := ipdb.NewDistrict("/path/to/quxian.ipdb")
if err != nil {
	log.Fatal(err)
}
fmt.Println(db.IsIPv4())    // check database support ip type
fmt.Println(db.IsIPv6())    // check database support ip type
fmt.Println(db.Languages()) // database support language
fmt.Println(db.Fields())    // database support fields

fmt.Println(db.Find("1.12.7.255", "CN"))
fmt.Println(db.FindMap("2001:250:200::", "CN"))
fmt.Println(db.FindInfo("1.12.7.255", "CN"))

fmt.Println()

适用于IPDB格式的基站 IPv4 库

db, err := ipdb.NewBaseStation("/path/to/station_ip.ipdb")
if err != nil {
	log.Fatal(err)
}

fmt.Println(db.FindMap("223.220.223.255", "CN"))
Issues
  • Fix Process crash when parsing the wrong DB file

    Fix Process crash when parsing the wrong DB file

    When we parse the DB file, the wrong DB file metaLength may be larger than the file size, and illegal address access may occur when calling 'json.Unmarshal' and be killed by the system.

    opened by fcharlie 3
  • Not use reflect create IPInfo object.

    Not use reflect create IPInfo object.

    func makeIPInfo(data string, languageOffset int, fields []string) *IPInfo {
    	info := new(IPInfo)
    	mapping := map[string]*string{
    		"country_name":     &info.CountryName,
    		"region_name":      &info.RegionName,
    		"city_name":        &info.CityName,
    		"owner_domain":     &info.OwnerDomain,
    		"isp_domain":       &info.IspDomain,
    		"latitude":         &info.Latitude,
    		"longitude":        &info.Longitude,
    		"timezone":         &info.Timezone,
    		"utc_offset":       &info.UtcOffset,
    		"china_admin_code": &info.ChinaAdminCode,
    		"idd_code":         &info.IddCode,
    		"country_code":     &info.CountryCode,
    		"continent_code":   &info.ContinentCode,
    		"idc":              &info.IDC,
    		"base_station":     &info.BaseStation,
    		"country_code3":    &info.CountryCode3,
    		"european_union":   &info.EuropeanUnion,
    		"currency_code":    &info.CurrencyCode,
    		"currency_name":    &info.CurrencyName,
    		"anycast":          &info.Anycast,
    	}
    	values := strings.Split(data, "\t")
    	values = values[languageOffset : languageOffset+len(fields)]
    	for index, value := range values {
    		name := fields[index]
    		*mapping[name] = value
    	}
    	return info
    }
    
    opened by septs 3
  • Is it possible to enumerate the values for ENUM-like fields in ipdb file?

    Is it possible to enumerate the values for ENUM-like fields in ipdb file?

    Is it possible to enumerate the values for those ENUM-like fields like region_name, city_name, isp_domain in the ipdb file, we found that is pretty useful as we need to map these values to our own data model. image

    opened by t-bzhan 1
  • 占用过多内存

    占用过多内存

    我们的服务部署在k8s上,使用后pods的内存增加了300多M,出现这个现象是使用的姿势不对吗 ipdbPath := os.Getenv("IP_CITY_PATH") _ipdb, _ := ipdb.NewCity(ipdbPath) ipInfo, _ := _ipdb.FindInfo(lastIp, "CN")

    opened by laokiea 1
  • Excellent ipdb file format!

    Excellent ipdb file format!

    How does this SDK find out the geo location of a given IP address? I'm curious about this and read the source. It's really a nice design! The most eye-catching and exciting part is file format. I draw it's layout as below:

    ipdb

    If I understand correctly, the green 1-byte between nodes area and records area is unused. Is this 1-byte hole necessary?

    :)

    opened by hzzb 0
  • 运营商中英文问题

    运营商中英文问题

    db.Find("183.195.52.13", "CN")

    我在mac上执行,返回结果是ok的,运营商字段返回移动,但是我部署到容器环境中,执行结果就有差异,运营商字段返回chinamobile.com,除了运营商字段,其他字段结果都是相同的,都是中文,造成这种差异的原因有哪些

    opened by yeyuqiu 2
Releases(v1.3.3)
Go package to simulate bandwidth, latency and packet loss for net.PacketConn and net.Conn interfaces

lossy Go package to simulate bandwidth, latency and packet loss for net.PacketConn and net.Conn interfaces. Its main usage is to test robustness of ap

Cevat Barış Yılmaz 308 Jul 5, 2022
Bridge facebook messenger with any service supported by matterbridge

fbridge fbridge bridges facebook messenger with any service supported by matterbridge trough the API interface. fbridge is using fbchat to connect to

null 25 Mar 17, 2022
easyRpc - Sync && Async Call supported

easyRpc - Sync && Async Call supported

Dub Dub 2 Feb 16, 2022
Microservice on IPv4: 3000 port without database. Upon request, returns the source JSON in the desired format

?? Этапы V1.0 Микросервис на IPv4:3000 порту без базы данных. По запросу возвращ

Eugene Sviat 0 Dec 22, 2021
A Go library for fetching, parsing, and updating RSS feeds.

rss RSS is a small library for simplifying the parsing of RSS and Atom feeds. The package could do with more testing, but it conforms to the RSS 1.0,

Jamie Hall 366 Aug 4, 2022
EasyNet - A light net library with epoll

easyNet - NON BLOCKING IO Examples echo-server package main import ( "fmt" "g

Dub Dub 5 Mar 3, 2022
Lux - A web library collection based on net/http

Lux - A web library collection based on net/http

serve-it-yourself 16 Aug 1, 2022
🔎Sniffing and parsing mysql,redis,http,mongodb etc protocol. 抓包截取项目中的数据库请求并解析成相应的语句。

go-sniffer Capture mysql,redis,http,mongodb etc protocol... 抓包截取项目中的数据库请求并解析成相应的语句,如mysql协议会解析为sql语句,便于调试。 不要修改代码,直接嗅探项目中的数据请求。 中文使用说明 Support List: m

Four 1.6k Aug 11, 2022
Peg, Parsing Expression Grammar, is an implementation of a Packrat parser generator.

PEG, an Implementation of a Packrat Parsing Expression Grammar in Go A Parsing Expression Grammar ( hence peg) is a way to create grammars similar in

Andrew Snodgrass 860 Aug 3, 2022
Kick dropper is a very simple and leightweight demonstration of SQL querying, and injection by parsing URl's

__ __ __ __ _____ ______ | |/ |__|.----.| |--.______| \.----.| |.-----.-----.-----.----.

RE43P3R 2 Feb 6, 2022
A yaml data-driven testing format together with golang testing library

Specified Yaml data-driven testing Specified is a yaml data format for data-driven testing. This enforces separation between feature being tested the

Design it, Run it 0 Jan 9, 2022
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

fasthttp Fast HTTP implementation for Go. Currently fasthttp is successfully used by VertaMedia in a production serving up to 200K rps from more than

Aliaksandr Valialkin 18.2k Aug 15, 2022
screen sharing for developers https://screego.net/

screego/server screen sharing for developers Huge thanks to sipgate for sponsoring this project! Intro In the past I've had some problems sharing my s

screego 4.9k Aug 10, 2022
ipx provides general purpose extensions to golang's IP functions in net package

ipx ipx is a library which provides a set of extensions on go's standart IP functions in net package. compability with net package ipx is fully compat

null 8 May 24, 2021
ConnPool is a thread safe connection pool for net.Conn interface.

ConnPool is a thread safe connection pool for net.Conn interface. It can be used to manage and reuse connections.

Burak Sezer 120 Aug 3, 2022
EasyTCP is a light-weight and less painful TCP server framework written in Go (Golang) based on the standard net package.

EasyTCP is a light-weight TCP framework written in Go (Golang), built with message router. EasyTCP helps you build a TCP server easily fast and less painful.

zxl 447 Aug 16, 2022
Fork of Go stdlib's net/http that works with alternative TLS libraries like refraction-networking/utls.

github.com/ooni/oohttp This repository contains a fork of Go's standard library net/http package including patches to allow using this HTTP code with

Open Observatory of Network Interference (OONI) 26 Jul 22, 2022
Drop-in replacement for Go net/http when running in AWS Lambda & API Gateway

Package gateway provides a drop-in replacement for net/http's ListenAndServe for use in AWS Lambda & API Gateway, simply swap it out for gateway.Liste

Apex 632 Aug 3, 2022