Documentation
¶
Overview ¶
Package getmyip returns public and outbound IP addresses of current machine.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // TimeOutGeolocation is the timeout for querying Geolocation API. TimeOutGeolocation = 15 * time.Second // TimeOutPublicIP is the timeout for querying Public IP API. TimeOutPublicIP = 10 * time.Second // TimeOutOutboundIP is the timeout for querying Outbound IP. TimeOutOutboundIP = 10 * time.Millisecond )
var DefaultGeolocationToken = GeolocationAccessTokens{
ServiceProviderIpapiCo: "",
ServiceProviderIpApiCom: "",
}
DefaultGeolocationToken contains access tokens for various Geolocation API, you may bring your own license by overriding this variable, leave it value empty if it requires no license.
Functions ¶
func GetOutboundIP ¶
GetOutboundIP retrieves preferred outbound IP address of current machine.
func GetPublicIP ¶
GetPublicIP retrieves public IPv4 address of current machine by calling various online services.
func GetPublicIPWithClient ¶ added in v0.0.4
GetPublicIPWithClient retrieves public IPv4 address of current machine by calling various online services with given client and timeout.
func IsPublicIP ¶ added in v0.0.10
IsPublicIP checks if the given IP is a public IP, i.e. not loopback, link-local, interface-local, unspecified, or multicast.
Types ¶
type Geolocation ¶ added in v0.0.3
type Geolocation struct { CountryCode string `json:"country_code,omitempty"` CountryFlag string `json:"country_flag,omitempty"` Country string `json:"country,omitempty"` Region string `json:"region,omitempty"` City string `json:"city,omitempty"` Latitude string `json:"latitude,omitempty"` Longitude string `json:"longitude,omitempty"` Carrier string `json:"carrier,omitempty"` ISP string `json:"isp,omitempty"` ASN string `json:"asn,omitempty"` }
Geolocation describes the deduced geographic position and ISP info of an IP address.
type GeolocationAccessTokens ¶ added in v0.0.3
type GeolocationAccessTokens map[GeolocationServiceProvider]string
GeolocationAccessTokens represents a mapping between geolocation service provider and access token to its service.
type GeolocationResult ¶ added in v0.0.3
type GeolocationResult map[GeolocationServiceProvider]*Geolocation
GeolocationResult represents a collection of geolocation result from various service providers.
func GetGeolocation ¶ added in v0.0.3
func GetGeolocation(ip net.IP, tokens ...GeolocationAccessTokens) (GeolocationResult, error)
GetGeolocation returns deduced geographic position of a given IP address from licensed service providers.
func (GeolocationResult) GetCity ¶ added in v0.0.10
func (g GeolocationResult) GetCity() string
GetCity returns the most frequent city name in the result.
func (GeolocationResult) GetCountryCode ¶ added in v0.0.10
func (g GeolocationResult) GetCountryCode() string
GetCountryCode returns the most frequent country code in the result.
func (GeolocationResult) String ¶ added in v0.0.3
func (g GeolocationResult) String() string
type GeolocationServiceProvider ¶ added in v0.0.3
type GeolocationServiceProvider string
GeolocationServiceProvider represents the name of service provider of Geolocation API.
const ( ServiceProviderIpregistry GeolocationServiceProvider = "ipregistry" ServiceProviderIpify GeolocationServiceProvider = "ipify" ServiceProviderIpapiCo GeolocationServiceProvider = "ipapico" ServiceProviderIpApiCom GeolocationServiceProvider = "ipapicom" ServiceProviderIpdata GeolocationServiceProvider = "ipdata" )
Name of service provider of Geolocation API