ip2location

package module
v9.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 21 Imported by: 56

README

Go Report Card PkgGoDev

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, usage type, address type and IAB category 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, usage type, address type and IAB category 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.

As an alternative, this package can also call the IP2Location Web Service. This requires an API key. If you don't have an existing API key, you can subscribe for one at the below:

https://www.ip2location.com/web-service/ip2location

Installation

go get github.com/ip2location/ip2location-go/v9

QUERY USING THE BIN FILE

Dependencies

This package requires IP2Location BIN data file to function. You may download the BIN data file at

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.

Methods

Below are the methods supported in this package.

Method Name Description
OpenDB Initialize the package with the BIN file.
Get_all Returns the geolocation information in an object.
Get_country_short Returns the country code.
Get_country_long Returns the country name.
Get_region Returns the region name.
Get_city Returns the city name.
Get_isp Returns the ISP name.
Get_latitude Returns the latitude.
Get_longitude Returns the longitude.
Get_domain Returns the domain name.
Get_zipcode Returns the ZIP code.
Get_timezone Returns the time zone.
Get_netspeed Returns the net speed.
Get_iddcode Returns the IDD code.
Get_areacode Returns the area code.
Get_weatherstationcode Returns the weather station code.
Get_weatherstationname Returns the weather station name.
Get_mcc Returns the mobile country code.
Get_mnc Returns the mobile network code.
Get_mobilebrand Returns the mobile brand.
Get_elevation Returns the elevation in meters.
Get_usagetype Returns the usage type.
Get_addresstype Returns the address type.
Get_category Returns the IAB category.
Close Closes BIN file.

Usage

package main

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

func main() {
	db, err := ip2location.OpenDB("./IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY.BIN")
	
	if err != nil {
		fmt.Print(err)
		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("addresstype: %s\n", results.Addresstype)
	fmt.Printf("category: %s\n", results.Category)
	fmt.Printf("api version: %s\n", ip2location.Api_version())
	
	db.Close()
}

QUERY USING THE IP2LOCATION WEB SERVICE

Methods

Below are the methods supported in this package.

Method Name Description
OpenWS 3 input parameters:
  1. IP2Location API Key.
  2. Package (WS1 - WS25)
  3. Use HTTPS or HTTP
LookUp Query IP address. This method returns an object containing the geolocation info.
  • country_code
  • country_name
  • region_name
  • city_name
  • latitude
  • longitude
  • zip_code
  • time_zone
  • isp
  • domain
  • net_speed
  • idd_code
  • area_code
  • weather_station_code
  • weather_station_name
  • mcc
  • mnc
  • mobile_brand
  • elevation
  • usage_type
  • address_type
  • category
  • continent
    • name
    • code
    • hemisphere
    • translations
  • country
    • name
    • alpha3_code
    • numeric_code
    • demonym
    • flag
    • capital
    • total_area
    • population
    • currency
      • code
      • name
      • symbol
    • language
      • code
      • name
    • idd_code
    • tld
    • is_eu
    • translations
  • region
    • name
    • code
    • translations
  • city
    • name
    • translations
  • geotargeting
    • metro
  • country_groupings
  • time_zone_info
    • olson
    • current_time
    • gmt_offset
    • is_dst
    • sunrise
    • sunset
    GetCredit This method returns the web service credit balance in an object.

    Usage

    package main
    
    import (
    	"github.com/ip2location/ip2location-go/v9"
    	"fmt"
    )
    
    func main() {
    	apikey := "YOUR_API_KEY"
    	apipackage := "WS25"
    	usessl := true
    	addon := "continent,country,region,city,geotargeting,country_groupings,time_zone_info" // leave blank if no need
    	lang := "en" // leave blank if no need
    	
    	ws, err := ip2location.OpenWS(apikey, apipackage, usessl)
    	
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    	ip := "8.8.8.8"
    	res, err := ws.LookUp(ip, addon, lang)
    
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    
    	if res.Response != "OK" {
    		fmt.Printf("Error: %s\n", res.Response)
    	} else {
    		// standard results
    		fmt.Printf("Response: %s\n", res.Response)
    		fmt.Printf("CountryCode: %s\n", res.CountryCode)
    		fmt.Printf("CountryName: %s\n", res.CountryName)
    		fmt.Printf("RegionName: %s\n", res.RegionName)
    		fmt.Printf("CityName: %s\n", res.CityName)
    		fmt.Printf("Latitude: %f\n", res.Latitude)
    		fmt.Printf("Longitude: %f\n", res.Longitude)
    		fmt.Printf("ZipCode: %s\n", res.ZipCode)
    		fmt.Printf("TimeZone: %s\n", res.TimeZone)
    		fmt.Printf("Isp: %s\n", res.Isp)
    		fmt.Printf("Domain: %s\n", res.Domain)
    		fmt.Printf("NetSpeed: %s\n", res.NetSpeed)
    		fmt.Printf("IddCode: %s\n", res.IddCode)
    		fmt.Printf("AreaCode: %s\n", res.AreaCode)
    		fmt.Printf("WeatherStationCode: %s\n", res.WeatherStationCode)
    		fmt.Printf("WeatherStationName: %s\n", res.WeatherStationName)
    		fmt.Printf("Mcc: %s\n", res.Mcc)
    		fmt.Printf("Mnc: %s\n", res.Mnc)
    		fmt.Printf("MobileBrand: %s\n", res.MobileBrand)
    		fmt.Printf("Elevation: %d\n", res.Elevation)
    		fmt.Printf("UsageType: %s\n", res.UsageType)
    		fmt.Printf("AddressType: %s\n", res.AddressType)
    		fmt.Printf("Category: %s\n", res.Category)
    		fmt.Printf("CategoryName: %s\n", res.CategoryName)
    		fmt.Printf("CreditsConsumed: %d\n", res.CreditsConsumed)
    		
    		// continent addon
    		fmt.Printf("Continent => Name: %s\n", res.Continent.Name)
    		fmt.Printf("Continent => Code: %s\n", res.Continent.Code)
    		fmt.Printf("Continent => Hemisphere: %+v\n", res.Continent.Hemisphere)
    		
    		// country addon
    		fmt.Printf("Country => Name: %s\n", res.Country.Name)
    		fmt.Printf("Country => Alpha3Code: %s\n", res.Country.Alpha3Code)
    		fmt.Printf("Country => NumericCode: %s\n", res.Country.NumericCode)
    		fmt.Printf("Country => Demonym: %s\n", res.Country.Demonym)
    		fmt.Printf("Country => Flag: %s\n", res.Country.Flag)
    		fmt.Printf("Country => Capital: %s\n", res.Country.Capital)
    		fmt.Printf("Country => TotalArea: %s\n", res.Country.TotalArea)
    		fmt.Printf("Country => Population: %s\n", res.Country.Population)
    		fmt.Printf("Country => IddCode: %s\n", res.Country.IddCode)
    		fmt.Printf("Country => Tld: %s\n", res.Country.Tld)
    		fmt.Printf("Country => IsEu: %t\n", res.Country.IsEu)
    		
    		fmt.Printf("Country => Currency => Code: %s\n", res.Country.Currency.Code)
    		fmt.Printf("Country => Currency => Name: %s\n", res.Country.Currency.Name)
    		fmt.Printf("Country => Currency => Symbol: %s\n", res.Country.Currency.Symbol)
    		
    		fmt.Printf("Country => Language => Code: %s\n", res.Country.Language.Code)
    		fmt.Printf("Country => Language => Name: %s\n", res.Country.Language.Name)
    		
    		// region addon
    		fmt.Printf("Region => Name: %s\n", res.Region.Name)
    		fmt.Printf("Region => Code: %s\n", res.Region.Code)
    		
    		// city addon
    		fmt.Printf("City => Name: %s\n", res.City.Name)
    		
    		// geotargeting addon
    		fmt.Printf("Geotargeting => Metro: %s\n", res.Geotargeting.Metro)
    		
    		// country_groupings addon
    		for i, s := range res.CountryGroupings {
    			fmt.Printf("CountryGroupings => #%d => Acronym: %s\n", i, s.Acronym)
    			fmt.Printf("CountryGroupings => #%d => Name: %s\n", i, s.Name)
    		}
    		
    		// time_zone_info addon
    		fmt.Printf("TimeZoneInfo => Olson: %s\n", res.TimeZoneInfo.Olson)
    		fmt.Printf("TimeZoneInfo => CurrentTime: %s\n", res.TimeZoneInfo.CurrentTime)
    		fmt.Printf("TimeZoneInfo => GmtOffset: %d\n", res.TimeZoneInfo.GmtOffset)
    		fmt.Printf("TimeZoneInfo => IsDst: %s\n", res.TimeZoneInfo.IsDst)
    		fmt.Printf("TimeZoneInfo => Sunrise: %s\n", res.TimeZoneInfo.Sunrise)
    		fmt.Printf("TimeZoneInfo => Sunset: %s\n", res.TimeZoneInfo.Sunset)
    	}
    
    	res2, err := ws.GetCredit()
    
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    	
    	fmt.Printf("Credit Balance: %d\n", res2.Response)
    }
    

    IPTOOLS CLASS

    Methods

    Below are the methods supported in this package.

    Method Name Description
    func (t *IPTools) IsIPv4(IP string) bool Returns true if string contains an IPv4 address. Otherwise false.
    func (t *IPTools) IsIPv6(IP string) bool Returns true if string contains an IPv6 address. Otherwise false.
    func (t *IPTools) IPv4ToDecimal(IP string) (*big.Int, error) Returns the IP number for an IPv4 address.
    func (t *IPTools) IPv6ToDecimal(IP string) (*big.Int, error) Returns the IP number for an IPv6 address.
    func (t *IPTools) DecimalToIPv4(IPNum *big.Int) (string, error) Returns the IPv4 address for the supplied IP number.
    func (t *IPTools) DecimalToIPv6(IPNum *big.Int) (string, error) Returns the IPv6 address for the supplied IP number.
    func (t *IPTools) CompressIPv6(IP string) (string, error) Returns the IPv6 address in compressed form.
    func (t *IPTools) ExpandIPv6(IP string) (string, error) Returns the IPv6 address in expanded form.
    func (t *IPTools) IPv4ToCIDR(IPFrom string, IPTo string) ([]string, error) Returns a list of CIDR from the supplied IPv4 range.
    func (t *IPTools) IPv6ToCIDR(IPFrom string, IPTo string) ([]string, error) Returns a list of CIDR from the supplied IPv6 range.
    func (t *IPTools) CIDRToIPv4(CIDR string) ([]string, error) Returns the IPv4 range from the supplied CIDR.
    func (t *IPTools) CIDRToIPv6(CIDR string) ([]string, error) Returns the IPv6 range from the supplied CIDR.

    Usage

    package main
    
    import (
    	"github.com/ip2location/ip2location-go/v9"
    	"fmt"
    	"math/big"
    )
    
    func main() {
    	t := ip2location.OpenTools()
    	
    	ip := "8.8.8.8"
    	res := t.IsIPv4(ip)
    	
    	fmt.Printf("Is IPv4: %t\n", res)
    	
    	ipnum, err := t.IPv4ToDecimal(ip)
    	if err != nil {
    		fmt.Print(err)
    	} else {
    		fmt.Printf("IPNum: %v\n", ipnum)
    	}
    
    	ip2 := "2600:1f18:45b0:5b00:f5d8:4183:7710:ceec"
    	res2 := t.IsIPv6(ip2)
    	
    	fmt.Printf("Is IPv6: %t\n", res2)
    
    	ipnum2, err := t.IPv6ToDecimal(ip2)
    	if err != nil {
    		fmt.Print(err)
    	} else {
    		fmt.Printf("IPNum: %v\n", ipnum2)
    	}
    	
    	ipnum3 := big.NewInt(42534)
    	res3, err := t.DecimalToIPv4(ipnum3)
    	
    	if err != nil {
    		fmt.Print(err)
    	} else {
    		fmt.Printf("IPv4: %v\n", res3)
    	}
    	
    	ipnum4, ok := big.NewInt(0).SetString("22398978840339333967292465152", 10)
    	if ok {
    		res4, err := t.DecimalToIPv6(ipnum4)
    		if err != nil {
    			fmt.Print(err)
    		} else {
    			fmt.Printf("IPv6: %v\n", res4)
    		}
    	}
    	
    	ip3 := "2600:1f18:045b:005b:f5d8:0:000:ceec"
    	res5, err := t.CompressIPv6(ip3)
    	
    	if err != nil {
    		fmt.Print(err)
    	} else {
    		fmt.Printf("Compressed: %v\n", res5)
    	}
    	
    	ip4 := "::45b:05b:f5d8:0:000:ceec"
    	res6, err := t.ExpandIPv6(ip4)
    	
    	if err != nil {
    		fmt.Print(err)
    	} else {
    		fmt.Printf("Expanded: %v\n", res6)
    	}
    	
    	res7, err := t.IPv4ToCIDR("10.0.0.0", "10.10.2.255")
    	
    	if err != nil {
    		fmt.Print(err)
    	} else {
    		for _, element := range res7 {
    			fmt.Println(element)
    		}
    	}
    	
    	res8, err := t.IPv6ToCIDR("2001:4860:4860:0000:0000:0000:0000:8888", "2001:4860:4860:0000:eeee:ffff:ffff:ffff")
    	
    	if err != nil {
    		fmt.Print(err)
    	} else {
    		for _, element := range res8 {
    			fmt.Println(element)
    		}
    	}
    	
    	res9, err := t.CIDRToIPv4("123.245.99.13/26")
    	
    	if err != nil {
    		fmt.Print(err)
    	} else {
    		fmt.Printf("IPv4 Range: %v\n", res9)
    	}
    	
    	res10, err := t.CIDRToIPv6("2002:1234::abcd:ffff:c0a8:101/62")
    	
    	if err != nil {
    		fmt.Print(err)
    	} else {
    		fmt.Printf("IPv6 Range: %v\n", res10)
    	}
    }
    

    COUNTRY CLASS

    Methods

    Below are the methods supported in this package.

    Method Name Description
    func OpenCountryInfo(csvFile string) (*CI, error) Expect a IP2Location Country Information CSV file. This database is free for download at https://www.ip2location.com/free/country-information
    func (c *CI) GetCountryInfo(countryCode ...string) ([]CountryInfoRecord, error) Returns the country information for specified country or all countries.

    Usage

    package main
    
    import (
    	"github.com/ip2location/ip2location-go"
    	"fmt"
    )
    
    func main() {
    	c, err := ip2location.OpenCountryInfo("./IP2LOCATION-COUNTRY-INFORMATION.CSV")
    
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    
    	res, err := c.GetCountryInfo("US")
    
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    
    	fmt.Printf("country_code: %s\n", res[0].Country_code)
    	fmt.Printf("country_name: %s\n", res[0].Country_name)
    	fmt.Printf("country_alpha3_code: %s\n", res[0].Country_alpha3_code)
    	fmt.Printf("country_numeric_code: %s\n", res[0].Country_numeric_code)
    	fmt.Printf("capital: %s\n", res[0].Capital)
    	fmt.Printf("country_demonym: %s\n", res[0].Country_demonym)
    	fmt.Printf("total_area: %s\n", res[0].Total_area)
    	fmt.Printf("population: %s\n", res[0].Population)
    	fmt.Printf("idd_code: %s\n", res[0].Idd_code)
    	fmt.Printf("currency_code: %s\n", res[0].Currency_code)
    	fmt.Printf("currency_name: %s\n", res[0].Currency_name)
    	fmt.Printf("currency_symbol: %s\n", res[0].Currency_symbol)
    	fmt.Printf("lang_code: %s\n", res[0].Lang_code)
    	fmt.Printf("lang_name: %s\n", res[0].Lang_name)
    	fmt.Printf("cctld: %s\n", res[0].Cctld)
    	fmt.Print("==============================================\n")
    
    	res2, err := c.GetCountryInfo()
    
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    
    	for _, v := range res2 {
    		fmt.Printf("country_code: %s\n", v.Country_code)
    		fmt.Printf("country_name: %s\n", v.Country_name)
    		fmt.Printf("country_alpha3_code: %s\n", v.Country_alpha3_code)
    		fmt.Printf("country_numeric_code: %s\n", v.Country_numeric_code)
    		fmt.Printf("capital: %s\n", v.Capital)
    		fmt.Printf("country_demonym: %s\n", v.Country_demonym)
    		fmt.Printf("total_area: %s\n", v.Total_area)
    		fmt.Printf("population: %s\n", v.Population)
    		fmt.Printf("idd_code: %s\n", v.Idd_code)
    		fmt.Printf("currency_code: %s\n", v.Currency_code)
    		fmt.Printf("currency_name: %s\n", v.Currency_name)
    		fmt.Printf("currency_symbol: %s\n", v.Currency_symbol)
    		fmt.Printf("lang_code: %s\n", v.Lang_code)
    		fmt.Printf("lang_name: %s\n", v.Lang_name)
    		fmt.Printf("cctld: %s\n", v.Cctld)
    		fmt.Print("==============================================\n")
    	}
    }
    

    REGION CLASS

    Methods

    Below are the methods supported in this package.

    Method Name Description
    func OpenRegionInfo(csvFile string) (*RI, error) Expect a IP2Location ISO 3166-2 Subdivision Code CSV file. This database is free for download at https://www.ip2location.com/free/iso3166-2
    func (r *RI) GetRegionCode(countryCode string, regionName string) (string, error) Returns the region code for the supplied country code and region name.

    Usage

    package main
    
    import (
    	"github.com/ip2location/ip2location-go"
    	"fmt"
    )
    
    func main() {
    	r, err := ip2location.OpenRegionInfo("./IP2LOCATION-ISO3166-2.CSV")
    
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    
    	res, err := r.GetRegionCode("US", "California")
    
    	if err != nil {
    		fmt.Print(err)
    		return
    	}
    
    	fmt.Printf("region code: %s\n", res)
    }
    

    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, usage type, address type and IAB category 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 CI added in v9.5.0

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

    The CI struct is the main object used to read the country information CSV.

    func OpenCountryInfo added in v9.5.0

    func OpenCountryInfo(csvFile string) (*CI, error)

    OpenCountryInfo initializes with the path to the country information CSV file.

    func (*CI) GetCountryInfo added in v9.5.0

    func (c *CI) GetCountryInfo(countryCode ...string) ([]CountryInfoRecord, error)

    GetCountryInfo returns the country information for the specified country or all countries if not specified

    type CountryInfoRecord added in v9.5.0

    type CountryInfoRecord struct {
    	Country_code         string
    	Country_name         string
    	Country_alpha3_code  string
    	Country_numeric_code string
    	Capital              string
    	Country_demonym      string
    	Total_area           string
    	Population           string
    	Idd_code             string
    	Currency_code        string
    	Currency_name        string
    	Currency_symbol      string
    	Lang_code            string
    	Lang_name            string
    	Cctld                string
    }

    The CountryInfoRecord struct stores all of the available country info found in the country information CSV file.

    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 OpenDBWithReader

    func OpenDBWithReader(reader DBReader) (*DB, error)

    OpenDBWithReader takes a DBReader 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_addresstype added in v9.1.0

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

    Get_addresstype will return the address type based on the queried IP address.

    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_category added in v9.1.0

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

    Get_category will return the category 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 DBReader

    type DBReader interface {
    	io.ReadCloser
    	io.ReaderAt
    }

    type IP2LocationCreditResult added in v9.2.0

    type IP2LocationCreditResult struct {
    	Response int `json:"response"`
    }

    The IP2LocationCreditResult struct stores the credit balance for the IP2Location Web Service.

    type IP2LocationResult added in v9.2.0

    type IP2LocationResult struct {
    	Response           string  `json:"response"`
    	CountryCode        string  `json:"country_code"`
    	CountryName        string  `json:"country_name"`
    	RegionName         string  `json:"region_name"`
    	CityName           string  `json:"city_name"`
    	Latitude           float64 `json:"latitude"`
    	Longitude          float64 `json:"longitude"`
    	ZipCode            string  `json:"zip_code"`
    	TimeZone           string  `json:"time_zone"`
    	Isp                string  `json:"isp"`
    	Domain             string  `json:"domain"`
    	NetSpeed           string  `json:"net_speed"`
    	IddCode            string  `json:"idd_code"`
    	AreaCode           string  `json:"area_code"`
    	WeatherStationCode string  `json:"weather_station_code"`
    	WeatherStationName string  `json:"weather_station_name"`
    	Mcc                string  `json:"mcc"`
    	Mnc                string  `json:"mnc"`
    	MobileBrand        string  `json:"mobile_brand"`
    	Elevation          int     `json:"elevation"`
    	UsageType          string  `json:"usage_type"`
    	AddressType        string  `json:"address_type"`
    	Category           string  `json:"category"`
    	CategoryName       string  `json:"category_name"`
    	Geotargeting       struct {
    		Metro string `json:"metro"`
    	} `json:"geotargeting"`
    	Continent struct {
    		Name       string   `json:"name"`
    		Code       string   `json:"code"`
    		Hemisphere []string `json:"hemisphere"`
    	} `json:"continent"`
    	Country struct {
    		Name        string `json:"name"`
    		Alpha3Code  string `json:"alpha3_code"`
    		NumericCode string `json:"numeric_code"`
    		Demonym     string `json:"demonym"`
    		Flag        string `json:"flag"`
    		Capital     string `json:"capital"`
    		TotalArea   string `json:"total_area"`
    		Population  string `json:"population"`
    		Currency    struct {
    			Code   string `json:"code"`
    			Name   string `json:"name"`
    			Symbol string `json:"symbol"`
    		} `json:"currency"`
    		Language struct {
    			Code string `json:"code"`
    			Name string `json:"name"`
    		} `json:"language"`
    		IddCode string `json:"idd_code"`
    		Tld     string `json:"tld"`
    		IsEu    bool   `json:"is_eu"`
    	} `json:"country"`
    	CountryGroupings []struct {
    		Acronym string `json:"acronym"`
    		Name    string `json:"name"`
    	} `json:"country_groupings"`
    	Region struct {
    		Name string `json:"name"`
    		Code string `json:"code"`
    	} `json:"region"`
    	City struct {
    		Name string `json:"name"`
    	} `json:"city"`
    	TimeZoneInfo struct {
    		Olson       string `json:"olson"`
    		CurrentTime string `json:"current_time"`
    		GmtOffset   int    `json:"gmt_offset"`
    		IsDst       string `json:"is_dst"`
    		Sunrise     string `json:"sunrise"`
    		Sunset      string `json:"sunset"`
    	} `json:"time_zone_info"`
    	CreditsConsumed int `json:"credits_consumed"`
    }

    The IP2LocationResult struct stores all of the available geolocation info found in the IP2Location Web Service.

    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
    }

    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.

    type IPTools added in v9.3.0

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

    The IPTools struct is the main object to access the IP address tools

    func OpenTools added in v9.3.0

    func OpenTools() *IPTools

    OpenTools initializes some variables

    func (*IPTools) CIDRToIPv4 added in v9.3.0

    func (t *IPTools) CIDRToIPv4(CIDR string) ([]string, error)

    CIDRToIPv4 returns the IPv4 range for the supplied CIDR.

    func (*IPTools) CIDRToIPv6 added in v9.3.0

    func (t *IPTools) CIDRToIPv6(CIDR string) ([]string, error)

    CIDRToIPv6 returns the IPv6 range for the supplied CIDR.

    func (*IPTools) CompressIPv6 added in v9.3.0

    func (t *IPTools) CompressIPv6(IP string) (string, error)

    CompressIPv6 returns the compressed form of the supplied IPv6 address.

    func (*IPTools) DecimalToIPv4 added in v9.3.0

    func (t *IPTools) DecimalToIPv4(IPNum *big.Int) (string, error)

    DecimalToIPv4 returns the IPv4 address for the supplied IP number.

    func (*IPTools) DecimalToIPv6 added in v9.3.0

    func (t *IPTools) DecimalToIPv6(IPNum *big.Int) (string, error)

    DecimalToIPv6 returns the IPv6 address for the supplied IP number.

    func (*IPTools) ExpandIPv6 added in v9.3.0

    func (t *IPTools) ExpandIPv6(IP string) (string, error)

    ExpandIPv6 returns the expanded form of the supplied IPv6 address.

    func (*IPTools) IPv4ToCIDR added in v9.3.0

    func (t *IPTools) IPv4ToCIDR(IPFrom string, IPTo string) ([]string, error)

    IPv4ToCIDR returns the CIDR for the supplied IPv4 range.

    func (*IPTools) IPv4ToDecimal added in v9.3.0

    func (t *IPTools) IPv4ToDecimal(IP string) (*big.Int, error)

    IPv4ToDecimal returns the IP number for the supplied IPv4 address.

    func (*IPTools) IPv6ToCIDR added in v9.3.0

    func (t *IPTools) IPv6ToCIDR(IPFrom string, IPTo string) ([]string, error)

    IPv6ToCIDR returns the CIDR for the supplied IPv6 range.

    func (*IPTools) IPv6ToDecimal added in v9.3.0

    func (t *IPTools) IPv6ToDecimal(IP string) (*big.Int, error)

    IPv6ToDecimal returns the IP number for the supplied IPv6 address.

    func (*IPTools) IsIPv4 added in v9.3.0

    func (t *IPTools) IsIPv4(IP string) bool

    IsIPv4 returns true if the IP address provided is an IPv4.

    func (*IPTools) IsIPv6 added in v9.3.0

    func (t *IPTools) IsIPv6(IP string) bool

    IsIPv6 returns true if the IP address provided is an IPv6.

    type RI added in v9.5.0

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

    The RI struct is the main object used to read the region information CSV.

    func OpenRegionInfo added in v9.5.0

    func OpenRegionInfo(csvFile string) (*RI, error)

    OpenRegionInfo initializes with the path to the region information CSV file.

    func (*RI) GetRegionCode added in v9.5.0

    func (r *RI) GetRegionCode(countryCode string, regionName string) (string, error)

    GetRegionCode returns the region code for the specified country and region name

    type RegionInfoRecord added in v9.5.0

    type RegionInfoRecord struct {
    	Country_code string
    	Name         string
    	Code         string
    }

    The RegionInfoRecord struct stores all of the available region info found in the region information CSV file.

    type WS added in v9.2.0

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

    The WS struct is the main object used to query the IP2Location Web Service.

    func OpenWS added in v9.2.0

    func OpenWS(apikey string, apipackage string, usessl bool) (*WS, error)

    OpenWS initializes with the web service API key, API package and whether to use SSL

    func (*WS) GetCredit added in v9.2.0

    func (w *WS) GetCredit() (IP2LocationCreditResult, error)

    GetCredit will return the web service credit balance.

    func (*WS) LookUp added in v9.2.0

    func (w *WS) LookUp(ipAddress string, addOn string, lang string) (IP2LocationResult, error)

    LookUp will return all geolocation fields based on the queried IP address, addon, lang

    Jump to

    Keyboard shortcuts

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