goip

package
v1.2.98 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

go-ip

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

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

import (
	"context"
	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",
		IpServiceUrl: "",
	}
	err := goip.Init(config)
	if err != nil {
		golog.WithTag("goip").Error(err.Error())
		return
	}

	ipinfo, err := goip.Default().GetIpLocation(context.Background(), "172.99.189.235")
	if err != nil {
		golog.WithTag("goip").Error(err.Error())
		return
	}

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

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

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

	ipInfo, err := goip.Default().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

func Init added in v1.2.88

func Init(configs ...Config) (err error)

可以一次初始化多个Redis实例或者 多次调用初始化多个实例

Types

type Config

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

type GoIp

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

func Default added in v1.2.88

func Default() *GoIp

func GetClient added in v1.2.88

func GetClient(names ...string) *GoIp

func New added in v1.2.88

func New(config Config) (*GoIp, error)

func (*GoIp) GetIpLocation added in v1.2.88

func (g *GoIp) GetIpLocation(ctx context.Context, ip string) (*IpLocation, error)

func (*GoIp) IsLocalIP added in v1.2.88

func (g *GoIp) IsLocalIP(ip net.IP) bool

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
}

type IpLocation added in v1.2.88

type IpLocation 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