goip

package
v1.2.65 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

go-ip

查询IP对应的国家 运营商等信息

https://www.ip2location.com/development-libraries/ip2location/go
package main

import (
	goip "github.com/gif-gif/go.io/go-ip"
	golog "github.com/gif-gif/go.io/go-log"
	"github.com/gif-gif/go.io/goio"
	"time"
)

func main() {
	goio.Init(goio.DEVELOPMENT)
	config := goip.Config{
		Mmdb:          "GeoLite2-Country.mmdb",
		Ip2locationDB: "IP-COUNTRY-REGION-CITY-ISP.BIN",
	}
	g := &goip.GoIp{}
	err := g.Init(config)
	if err != nil {
		golog.WithTag("goip").Error(err.Error())
		return
	}

	ipZhInfo, err := g.QueryDbReaderCountryForZhName("172.99.189.235")
	if err != nil {
		golog.WithTag("goip").Error(err.Error())
		return
	}

	golog.WithTag("goip").Info(ipZhInfo)

	ipInfo, err := g.QueryLocationInfoByIp("172.99.189.235")
	if err != nil {
		golog.WithTag("goip").Error(err.Error())
		return
	}

	golog.WithTag("goip").Info(ipInfo)

	time.Sleep(time.Second * 5)

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Mmdb          string `yaml:"Mmdb" json:"mmdb,optional"`
	Ip2locationDB string `yaml:"Ip2locationDB" json:"ip2locationDB,optional"`
}

type GoIp

type GoIp struct {
	// contains filtered or unexported fields
}

func (*GoIp) Init

func (g *GoIp) Init(config Config) error

func (*GoIp) QueryDbReaderCountryForZhName

func (g *GoIp) QueryDbReaderCountryForZhName(ipStr string) (*IpCountry, error)

查询 IP相关信息,返回IP所属国家中文名称

func (*GoIp) QueryLocationInfoByIp

func (g *GoIp) QueryLocationInfoByIp(ipStr string) (*IP2Locationrecord, error)

IP 相关信息

type IP2Locationrecord

type IP2Locationrecord struct {
	Country_short      string
	Country_long       string
	Region             string
	City               string
	Isp                string
	Latitude           float32
	Longitude          float32
	Domain             string
	Zipcode            string
	Timezone           string
	Netspeed           string
	Iddcode            string
	Areacode           string
	Weatherstationcode string
	Weatherstationname string
	Mcc                string
	Mnc                string
	Mobilebrand        string
	Elevation          float32
	Usagetype          string
	Addresstype        string
	Category           string
	District           string
	Asn                string
	As                 string
}

type IpCountry

type IpCountry struct {
	IsoCode       string `json:"iso_code"` //iso 编码 https://zh.m.wikipedia.org/zh/ISO_3166-1
	Name          string `json:"name"`
	Continent     string `json:"continent"`      //洲
	ContinentCode string `json:"continent_code"` //洲编码
	Isp           string `json:"isp"`            //isp
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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