ipsrv

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

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

Go to latest
Published: Aug 16, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

ipsrvdb-go

Feature

  1. Support IPv4 & IPv6.
  2. Support output db date, description and header.
  3. Support output raw IP info and IP info in a map.
  4. Support load the database into memory or using MMAP.

Installing

go get github.com/ipsrv/ipsrvdb-go

Example

package main

import (
	"fmt"
	"github.com/ipsrv/ipsrvdb-go"
)

func main() {
	var db ipsrv.IPSrvDB
    db.Filename = "/path/to/ipsrv.dat"
    db.Mode = "mmap"
    db.Open()
    fmt.Println(db.Find("8.8.8.255"))
    fmt.Println(db.Findx("8.8.8.255"))
    fmt.Println(db.GetHeader(), db.GetDate(), db.GetDescription())
    db.Close()
}

Output

NA,北美洲,US,美国,,,,,,
map[country_iso_code:US isp_zh: country_zh:美国 province_iso_code: province_zh: city_code: city_zh: org: continent_code:NA continent_zh:北美洲]
continent_code,continent_zh,country_iso_code,country_zh,province_iso_code,province_zh,city_code,city_zh,isp_zh,org 20210811 IPSrv, Inc. Dat database.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes4ToInt

func Bytes4ToInt(b []byte) int64

func Bytes8ToInt

func Bytes8ToInt(b []byte) int

func BytesToInt

func BytesToInt(b []byte) int

func Cmp

func Cmp(a []byte, b []byte) int

Types

type IPSrvDB

type IPSrvDB struct {
	Filename    string
	Mode        string
	M           *mmap.ReaderAt
	F           *os.File
	IndexSize   int
	DataSize    int
	IndexEnd    int
	HeaderSize  int
	Header      string
	Date        string
	Description string
	Buf         []byte
	Len         int
}

func (*IPSrvDB) Close

func (db *IPSrvDB) Close()

func (*IPSrvDB) Data

func (db *IPSrvDB) Data(start, end int) []byte

func (*IPSrvDB) Find

func (db *IPSrvDB) Find(ipstr string) string

func (*IPSrvDB) Findx

func (db *IPSrvDB) Findx(ipstr string) map[string]string

func (*IPSrvDB) GetDate

func (db *IPSrvDB) GetDate() string

func (*IPSrvDB) GetDescription

func (db *IPSrvDB) GetDescription() string

func (*IPSrvDB) GetHeader

func (db *IPSrvDB) GetHeader() string

func (*IPSrvDB) GetLen

func (db *IPSrvDB) GetLen() int

func (*IPSrvDB) Index

func (db *IPSrvDB) Index(start, end int) []byte

func (*IPSrvDB) Open

func (db *IPSrvDB) Open()

func (*IPSrvDB) ReadAt

func (db *IPSrvDB) ReadAt(b []byte, off int64) (n int, err error)

Jump to

Keyboard shortcuts

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