ipdb

package module
v0.0.0-...-fd28f06 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2020 License: MIT Imports: 11 Imported by: 0

README

Package ipdb

Go Report Card GoDoc PkgGoDev

Package ipdb provides facilities for parsing IPDB files served by ipip.net, (maybe) works better than the official package. Compared to the official implementation, it provides some easier ways to look into the database, and allows you to focus more on your project without hesitation.

Getting started

  • Get any IPDB database files from ipip.net or somewhere else.
  • API documentation are available via GoDoc or PkgGoDev.
  • (optional) Know something about iptree.
  • (optional) Read the overview from inside an IPDB file.

Status

It comes to us the initial commit, with very few codes. This project is under developing, you may make any pull requests to add features or sending ideas by writing issues.

Documentation

Overview

Package ipdb provides facilities for parsing IPDB files served by ipip.net, (maybe) works better than the official package. Compared to the official implementation, it provides some easier ways to look into the database, and allows you to focus more on your project without hesitation.

A simple way to make queries to the database is, of course the database must be loaded in “IPDb”, Search the IP, then pass the return value as offset and Get what you want.

Besides, the implementation of iptree (type Node and Leaf) is to help buiding the full database in to an binary tree, maybe useful in some particular situations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPDb

type IPDb struct {
	FileSize uint64
	Metadata Metadata
	Data     []byte
	// contains filtered or unexported fields
}

IPDb stores the whole IPDB file

func NewIPDb

func NewIPDb(filepath string) (*IPDb, error)

NewIPDb reads the IPDB file by providing filepath, returning an IPDb instance or error.

func (*IPDb) GetAllFields

func (d *IPDb) GetAllFields(offset uint32) (map[string]map[string]string, error)

GetAllFields returns the data mapping by giving the offset, or error. BE AWARE: The return value stores the data in the form “map[field]map[lang]data”.

func (*IPDb) GetAllFieldsLocale

func (d *IPDb) GetAllFieldsLocale(offset uint32, lang string) (map[string]string, error)

GetAllFieldsLocale returns the data mapping by giving the offset, in the providing locale “lang”, or error.

func (*IPDb) GetBuildTime

func (d *IPDb) GetBuildTime() time.Time

GetBuildTime converts build number in metadata into time.Time.

func (*IPDb) GetLanguages

func (d *IPDb) GetLanguages() []string

GetLanguages returns the languages supported by the database.

func (*IPDb) GetRaw

func (d *IPDb) GetRaw(offset uint32) ([]byte, error)

GetRaw returns the raw data by giving the offset, or error.

func (*IPDb) GetValue

func (d *IPDb) GetValue(offset uint32, field string) (map[string]string, error)

GetValue returns the values in all locale, by giving offset and field, or error.

func (*IPDb) GetValueLocale

func (d *IPDb) GetValueLocale(offset uint32, field, lang string) (string, error)

GetValueLocale returns the values in the providing locale “lang”, by giving offset and field, or error.

func (*IPDb) GrowTree

func (d *IPDb) GrowTree() (*iptree.Node, error)

GrowTree return the root Node of the iptree.

func (*IPDb) IsIPv4Db

func (d *IPDb) IsIPv4Db() bool

IsIPv4Db checks if the database an IPv4 database.

func (*IPDb) IsIPv6Db

func (d *IPDb) IsIPv6Db() bool

IsIPv6Db checks if the database an IPv6 database.

func (*IPDb) Search

func (d *IPDb) Search(ip net.IP) (uint32, error)

Search the database for the providing ip, returning the offset in the database referring to the data, or error.

type Metadata

type Metadata struct {
	Build     int64          `json:"build"`
	IPVersion uint16         `json:"ip_version"`
	Languages map[string]int `json:"languages"`
	NodeCount uint32         `json:"node_count"`
	TotalSize uint64         `json:"total_size"`
	Fields    []string       `json:"fields"`
}

Metadata stores the metadata of the IPDB file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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