ip2location

package module
v8.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2020 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() {
	db, err := ip2location.OpenDB("./IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN")
	
	if err != nil {
		return
	}
	ip := "8.8.8.8"
	results, err := db.Get_all(ip)
	
	if err != nil {
		fmt.Print(err)
		return
	}
	
	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())
	
	db.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) 2020 by IP2Location.com, support@ip2location.com

Documentation

Overview

This ip2location 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Api_version

func Api_version() string

Api_version returns the version of the component.

func Close deprecated

func Close()

Close will close the file handle to the BIN file.

Deprecated: No longer being updated.

func Open deprecated

func Open(dbpath string)

Open takes the path to the IP2Location BIN database file. It will read all the metadata required to be able to extract the embedded geolocation data.

Deprecated: No longer being updated.

func Printrecord

func Printrecord(x IP2Locationrecord)

Printrecord is used to output the geolocation data for debugging purposes.

Types

type DB

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

func OpenDB

func OpenDB(dbpath string) (*DB, error)

Open takes the path to the IP2Location BIN database file. It will read all the metadata required to be able to extract the embedded geolocation data, and return the underlining DB object.

func (*DB) Close

func (d *DB) Close()

func (*DB) Get_all

func (d *DB) Get_all(ipaddress string) (IP2Locationrecord, error)

Get_all will return all geolocation fields based on the queried IP address.

func (*DB) Get_areacode

func (d *DB) Get_areacode(ipaddress string) (IP2Locationrecord, error)

Get_areacode will return the area code based on the queried IP address.

func (*DB) Get_city

func (d *DB) Get_city(ipaddress string) (IP2Locationrecord, error)

Get_city will return the city name based on the queried IP address.

func (*DB) Get_country_long

func (d *DB) Get_country_long(ipaddress string) (IP2Locationrecord, error)

Get_country_long will return the country name based on the queried IP address.

func (*DB) Get_country_short

func (d *DB) Get_country_short(ipaddress string) (IP2Locationrecord, error)

Get_country_short will return the ISO-3166 country code based on the queried IP address.

func (*DB) Get_domain

func (d *DB) Get_domain(ipaddress string) (IP2Locationrecord, error)

Get_domain will return the domain name based on the queried IP address.

func (*DB) Get_elevation

func (d *DB) Get_elevation(ipaddress string) (IP2Locationrecord, error)

Get_elevation will return the elevation in meters based on the queried IP address.

func (*DB) Get_iddcode

func (d *DB) Get_iddcode(ipaddress string) (IP2Locationrecord, error)

Get_iddcode will return the International Direct Dialing code based on the queried IP address.

func (*DB) Get_isp

func (d *DB) Get_isp(ipaddress string) (IP2Locationrecord, error)

Get_isp will return the Internet Service Provider name based on the queried IP address.

func (*DB) Get_latitude

func (d *DB) Get_latitude(ipaddress string) (IP2Locationrecord, error)

Get_latitude will return the latitude based on the queried IP address.

func (*DB) Get_longitude

func (d *DB) Get_longitude(ipaddress string) (IP2Locationrecord, error)

Get_longitude will return the longitude based on the queried IP address.

func (*DB) Get_mcc

func (d *DB) Get_mcc(ipaddress string) (IP2Locationrecord, error)

Get_mcc will return the mobile country code based on the queried IP address.

func (*DB) Get_mnc

func (d *DB) Get_mnc(ipaddress string) (IP2Locationrecord, error)

Get_mnc will return the mobile network code based on the queried IP address.

func (*DB) Get_mobilebrand

func (d *DB) Get_mobilebrand(ipaddress string) (IP2Locationrecord, error)

Get_mobilebrand will return the mobile carrier brand based on the queried IP address.

func (*DB) Get_netspeed

func (d *DB) Get_netspeed(ipaddress string) (IP2Locationrecord, error)

Get_netspeed will return the Internet connection speed based on the queried IP address.

func (*DB) Get_region

func (d *DB) Get_region(ipaddress string) (IP2Locationrecord, error)

Get_region will return the region name based on the queried IP address.

func (*DB) Get_timezone

func (d *DB) Get_timezone(ipaddress string) (IP2Locationrecord, error)

Get_timezone will return the time zone based on the queried IP address.

func (*DB) Get_usagetype

func (d *DB) Get_usagetype(ipaddress string) (IP2Locationrecord, error)

Get_usagetype will return the usage type based on the queried IP address.

func (*DB) Get_weatherstationcode

func (d *DB) Get_weatherstationcode(ipaddress string) (IP2Locationrecord, error)

Get_weatherstationcode will return the weather station code based on the queried IP address.

func (*DB) Get_weatherstationname

func (d *DB) Get_weatherstationname(ipaddress string) (IP2Locationrecord, error)

Get_weatherstationname will return the weather station name based on the queried IP address.

func (*DB) Get_zipcode

func (d *DB) Get_zipcode(ipaddress string) (IP2Locationrecord, error)

Get_zipcode will return the postal code based on the queried IP address.

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
}

The IP2Locationrecord struct stores all of the available geolocation info found in the IP2Location database.

func Get_all deprecated

func Get_all(ipaddress string) IP2Locationrecord

Get_all will return all geolocation fields based on the queried IP address.

Deprecated: No longer being updated.

func Get_areacode deprecated

func Get_areacode(ipaddress string) IP2Locationrecord

Get_areacode will return the area code based on the queried IP address.

Deprecated: No longer being updated.

func Get_city deprecated

func Get_city(ipaddress string) IP2Locationrecord

Get_city will return the city name based on the queried IP address.

Deprecated: No longer being updated.

func Get_country_long deprecated

func Get_country_long(ipaddress string) IP2Locationrecord

Get_country_long will return the country name based on the queried IP address.

Deprecated: No longer being updated.

func Get_country_short deprecated

func Get_country_short(ipaddress string) IP2Locationrecord

Get_country_short will return the ISO-3166 country code based on the queried IP address.

Deprecated: No longer being updated.

func Get_domain deprecated

func Get_domain(ipaddress string) IP2Locationrecord

Get_domain will return the domain name based on the queried IP address.

Deprecated: No longer being updated.

func Get_elevation deprecated

func Get_elevation(ipaddress string) IP2Locationrecord

Get_elevation will return the elevation in meters based on the queried IP address.

Deprecated: No longer being updated.

func Get_iddcode deprecated

func Get_iddcode(ipaddress string) IP2Locationrecord

Get_iddcode will return the International Direct Dialing code based on the queried IP address.

Deprecated: No longer being updated.

func Get_isp deprecated

func Get_isp(ipaddress string) IP2Locationrecord

Get_isp will return the Internet Service Provider name based on the queried IP address.

Deprecated: No longer being updated.

func Get_latitude deprecated

func Get_latitude(ipaddress string) IP2Locationrecord

Get_latitude will return the latitude based on the queried IP address.

Deprecated: No longer being updated.

func Get_longitude deprecated

func Get_longitude(ipaddress string) IP2Locationrecord

Get_longitude will return the longitude based on the queried IP address.

Deprecated: No longer being updated.

func Get_mcc deprecated

func Get_mcc(ipaddress string) IP2Locationrecord

Get_mcc will return the mobile country code based on the queried IP address.

Deprecated: No longer being updated.

func Get_mnc deprecated

func Get_mnc(ipaddress string) IP2Locationrecord

Get_mnc will return the mobile network code based on the queried IP address.

Deprecated: No longer being updated.

func Get_mobilebrand deprecated

func Get_mobilebrand(ipaddress string) IP2Locationrecord

Get_mobilebrand will return the mobile carrier brand based on the queried IP address.

Deprecated: No longer being updated.

func Get_netspeed deprecated

func Get_netspeed(ipaddress string) IP2Locationrecord

Get_netspeed will return the Internet connection speed based on the queried IP address.

Deprecated: No longer being updated.

func Get_region deprecated

func Get_region(ipaddress string) IP2Locationrecord

Get_region will return the region name based on the queried IP address.

Deprecated: No longer being updated.

func Get_timezone deprecated

func Get_timezone(ipaddress string) IP2Locationrecord

Get_timezone will return the time zone based on the queried IP address.

Deprecated: No longer being updated.

func Get_usagetype deprecated

func Get_usagetype(ipaddress string) IP2Locationrecord

Get_usagetype will return the usage type based on the queried IP address.

Deprecated: No longer being updated.

func Get_weatherstationcode deprecated

func Get_weatherstationcode(ipaddress string) IP2Locationrecord

Get_weatherstationcode will return the weather station code based on the queried IP address.

Deprecated: No longer being updated.

func Get_weatherstationname deprecated

func Get_weatherstationname(ipaddress string) IP2Locationrecord

Get_weatherstationname will return the weather station name based on the queried IP address.

Deprecated: No longer being updated.

func Get_zipcode deprecated

func Get_zipcode(ipaddress string) IP2Locationrecord

Get_zipcode will return the postal code based on the queried IP address.

Deprecated: No longer being updated.

Jump to

Keyboard shortcuts

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