ip2location

package module
v0.0.0-...-2ea55a1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 21 Imported by: 0

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, IAB category, district, autonomous system number (ASN) and autonomous system (AS) 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

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

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

func OpenCountryInfo

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

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

func (*CI) GetCountryInfo

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

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) DatabaseVersion

func (d *DB) DatabaseVersion() string

DatabaseVersion returns the database version.

func (*DB) Get_addresstype

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_as

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

Get_as will return the autonomous system (AS) based on the queried IP address.

func (*DB) Get_asn

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

Get_asn will return the autonomous system number (ASN) based on the queried IP address.

func (*DB) Get_category

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_district

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

Get_district will return the district name 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.

func (*DB) PackageVersion

func (d *DB) PackageVersion() string

PackageVersion returns the database type.

type DBReader

type DBReader interface {
	io.ReadCloser
	io.ReaderAt
}

type IP2LocationCreditResult

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

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

type IP2LocationResult

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
	District           string
	Asn                string
	As                 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

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

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

func OpenTools

func OpenTools() *IPTools

OpenTools initializes some variables

func (*IPTools) CIDRToIPv4

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

CIDRToIPv4 returns the IPv4 range for the supplied CIDR.

func (*IPTools) CIDRToIPv6

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

CIDRToIPv6 returns the IPv6 range for the supplied CIDR.

func (*IPTools) CompressIPv6

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

CompressIPv6 returns the compressed form of the supplied IPv6 address.

func (*IPTools) DecimalToIPv4

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

DecimalToIPv4 returns the IPv4 address for the supplied IP number.

func (*IPTools) DecimalToIPv6

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

DecimalToIPv6 returns the IPv6 address for the supplied IP number.

func (*IPTools) ExpandIPv6

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

ExpandIPv6 returns the expanded form of the supplied IPv6 address.

func (*IPTools) IPv4ToCIDR

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

IPv4ToCIDR returns the CIDR for the supplied IPv4 range.

func (*IPTools) IPv4ToDecimal

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

IPv4ToDecimal returns the IP number for the supplied IPv4 address.

func (*IPTools) IPv6ToCIDR

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

IPv6ToCIDR returns the CIDR for the supplied IPv6 range.

func (*IPTools) IPv6ToDecimal

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

IPv6ToDecimal returns the IP number for the supplied IPv6 address.

func (*IPTools) IsIPv4

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

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

func (*IPTools) IsIPv6

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

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

type RI

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

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

func OpenRegionInfo

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

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

func (*RI) GetRegionCode

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

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

type RegionInfoRecord

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

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

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

func OpenWS

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

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

GetCredit will return the web service credit balance.

func (*WS) LookUp

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