ip2location

package module
v8.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: MIT Imports: 8 Imported by: 0

README

Go Report Card

IP2Location Go Package

This Go package provides a fast lookup of country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code, station name, mcc, mnc, mobile brand, elevation, and usage type from IP address by using IP2Location database. This package uses a file based database available at IP2Location.com. This database simply contains IP blocks as keys, and other information such as country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code, station name, mcc, mnc, mobile brand, elevation, and usage type as values. It supports both IP address in IPv4 and IPv6.

This package can be used in many types of projects such as:

  • select the geographically closest mirror
  • analyze your web server logs to determine the countries of your visitors
  • credit card fraud detection
  • software export controls
  • display native language and currency
  • prevent password sharing and abuse of service
  • geotargeting in advertisement

The database will be updated in monthly basis for the greater accuracy. Free LITE databases are available at https://lite.ip2location.com/ upon registration.

The paid databases are available at https://www.ip2location.com under Premium subscription package.

Installation

go get github.com/ip2location/ip2location-go

Example

package main

import (
	"fmt"
	"github.com/ip2location/ip2location-go"
)

func main() {
	ip2location.Open("./IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN")
	ip := "8.8.8.8"
	
	results := ip2location.Get_all(ip)
	
	fmt.Printf("country_short: %s\n", results.Country_short)
	fmt.Printf("country_long: %s\n", results.Country_long)
	fmt.Printf("region: %s\n", results.Region)
	fmt.Printf("city: %s\n", results.City)
	fmt.Printf("isp: %s\n", results.Isp)
	fmt.Printf("latitude: %f\n", results.Latitude)
	fmt.Printf("longitude: %f\n", results.Longitude)
	fmt.Printf("domain: %s\n", results.Domain)
	fmt.Printf("zipcode: %s\n", results.Zipcode)
	fmt.Printf("timezone: %s\n", results.Timezone)
	fmt.Printf("netspeed: %s\n", results.Netspeed)
	fmt.Printf("iddcode: %s\n", results.Iddcode)
	fmt.Printf("areacode: %s\n", results.Areacode)
	fmt.Printf("weatherstationcode: %s\n", results.Weatherstationcode)
	fmt.Printf("weatherstationname: %s\n", results.Weatherstationname)
	fmt.Printf("mcc: %s\n", results.Mcc)
	fmt.Printf("mnc: %s\n", results.Mnc)
	fmt.Printf("mobilebrand: %s\n", results.Mobilebrand)
	fmt.Printf("elevation: %f\n", results.Elevation)
	fmt.Printf("usagetype: %s\n", results.Usagetype)
	fmt.Printf("api version: %s\n", ip2location.Api_version())
	
	ip2location.Close()
}

Dependencies

The complete database is available at https://www.ip2location.com under subscription package.

IPv4 BIN vs IPv6 BIN

Use the IPv4 BIN file if you just need to query IPv4 addresses. Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.

Copyright (C) 2019 by IP2Location.com, support@ip2location.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Api_version

func Api_version() string

get api version

func Close

func Close()

close database file handle

func Open

func Open(dbpath string)

initialize the component with the database path

func Printrecord

func Printrecord(x IP2Locationrecord)

for debugging purposes

Types

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
}

func Get_all

func Get_all(ipaddress string) IP2Locationrecord

get all fields

func Get_areacode

func Get_areacode(ipaddress string) IP2Locationrecord

get area code

func Get_city

func Get_city(ipaddress string) IP2Locationrecord

get city

func Get_country_long

func Get_country_long(ipaddress string) IP2Locationrecord

get country name

func Get_country_short

func Get_country_short(ipaddress string) IP2Locationrecord

get country code

func Get_domain

func Get_domain(ipaddress string) IP2Locationrecord

get domain

func Get_elevation

func Get_elevation(ipaddress string) IP2Locationrecord

get elevation

func Get_iddcode

func Get_iddcode(ipaddress string) IP2Locationrecord

get idd code

func Get_isp

func Get_isp(ipaddress string) IP2Locationrecord

get isp

func Get_latitude

func Get_latitude(ipaddress string) IP2Locationrecord

get latitude

func Get_longitude

func Get_longitude(ipaddress string) IP2Locationrecord

get longitude

func Get_mcc

func Get_mcc(ipaddress string) IP2Locationrecord

get mobile country code

func Get_mnc

func Get_mnc(ipaddress string) IP2Locationrecord

get mobile network code

func Get_mobilebrand

func Get_mobilebrand(ipaddress string) IP2Locationrecord

get mobile carrier brand

func Get_netspeed

func Get_netspeed(ipaddress string) IP2Locationrecord

get net speed

func Get_region

func Get_region(ipaddress string) IP2Locationrecord

get region

func Get_timezone

func Get_timezone(ipaddress string) IP2Locationrecord

get time zone

func Get_usagetype

func Get_usagetype(ipaddress string) IP2Locationrecord

get usage type

func Get_weatherstationcode

func Get_weatherstationcode(ipaddress string) IP2Locationrecord

get weather station code

func Get_weatherstationname

func Get_weatherstationname(ipaddress string) IP2Locationrecord

get weather station name

func Get_zipcode

func Get_zipcode(ipaddress string) IP2Locationrecord

get zip code

Jump to

Keyboard shortcuts

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