All Projects → ipinfo → go

ipinfo / go

Licence: Apache-2.0 license
Go library for IPinfo API (IP geolocation and other types of IP data)

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to go

cli
Official Command Line Interface for the IPinfo API (IP geolocation and other types of IP data)
Stars: ✭ 1,279 (+1582.89%)
Mutual labels:  ipinfo, ip-address, ip-geolocation, ip-data
rails
Official Rails Library for IPinfo API (IP geolocation and other types of IP data)
Stars: ✭ 16 (-78.95%)
Mutual labels:  ipinfo, ip-address, ip-geolocation, ip-data
laravel
Official Laravel client library for IPinfo API (IP geolocation and other types of IP data)
Stars: ✭ 80 (+5.26%)
Mutual labels:  ipinfo, ip-address, ip-geolocation, ip-data
django
Official Django Library for IPinfo API (IP geolocation and other types of IP data)
Stars: ✭ 36 (-52.63%)
Mutual labels:  ipinfo, ip-address, ip-geolocation
ruby
Official Ruby client library for IPinfo API (IP geolocation and other types of IP data)
Stars: ✭ 42 (-44.74%)
Mutual labels:  ipinfo, ip-address, ip-geolocation
ipapi-python
Python bindings for https://ipapi.co (IP Address Location) - Use with python / django / flask for IP address location lookup
Stars: ✭ 42 (-44.74%)
Mutual labels:  ip-address, ip-geolocation
Geolocate-IP-Browser-Extension
A browser extension, which shows you the origin of your IP address.
Stars: ✭ 21 (-72.37%)
Mutual labels:  ip-address, ip-geolocation
termux-snippets
An integrated tool and a collection of snippets which helps in the various aspects of the terminal.
Stars: ✭ 28 (-63.16%)
Mutual labels:  ipinfo
IPASN-History
IP ASN History to find ASN announcing an IP and the closest prefix announcing it at a specific date
Stars: ✭ 76 (+0%)
Mutual labels:  ip-address
larinfo
Display system information (IP address, OS, versions) for Laravel.
Stars: ✭ 32 (-57.89%)
Mutual labels:  ipinfo
Python
Official Python Library for IPinfo API (IP geolocation and other types of IP data)
Stars: ✭ 164 (+115.79%)
Mutual labels:  ip-address
node-ip2region
IP/IPv6 to region on Node.js (IP/IPv6 地址到区域运营商)
Stars: ✭ 95 (+25%)
Mutual labels:  ip-address
ip2location-piwik
Use IP2Location geolocation database to lookup for accurate visitor location in Matomo (Piwik) 3.x. It enables the user to find the country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation, usage type, address type and IAB category that any IP address o…
Stars: ✭ 26 (-65.79%)
Mutual labels:  ip-geolocation
ip2location-lua
Use IP2Location geolocation database to lookup the geolocation information with IP2Location Lua Package. It can be used to determine country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation, usage type, address type and IAB category that any IP address …
Stars: ✭ 14 (-81.58%)
Mutual labels:  ip-geolocation
private-ip
Check if IP address is private.
Stars: ✭ 26 (-65.79%)
Mutual labels:  ip-address
Ipaddress
Java library for handling IP addresses and subnets, both IPv4 and IPv6
Stars: ✭ 197 (+159.21%)
Mutual labels:  ip-address
ipinfo
A wrapper around the ipinfo.io services
Stars: ✭ 51 (-32.89%)
Mutual labels:  ipinfo
cs-wordpress-bouncer
CrowdSec is an open-source cyber security tool. This plugin blocks detected attackers or display them a captcha to check they are not bots.
Stars: ✭ 25 (-67.11%)
Mutual labels:  ip-address
osint-combiner
Combining OSINT sources in Elastic Stack
Stars: ✭ 77 (+1.32%)
Mutual labels:  ipinfo
ip2location-csv-converter
This PHP script converts IP2Location CSV database into IP range or CIDR format.
Stars: ✭ 26 (-65.79%)
Mutual labels:  ip-geolocation

IPinfo IPinfo Go Client Library

License Go Reference

This is the official Go client library for the IPinfo.io IP address API, allowing you to lookup your own IP address, or get any of the following details for other IP addresses:

  • IP to Geolocation (city, region, country, postal code, latitude and longitude)
  • IP to ASN (ISP or network operator, associated domain name, and type, such as business, hosting or company)
  • IP to Company (the name and domain of the business that uses the IP address)
  • IP to Carrier (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)

Check all the data we have for your IP address here.

Getting Started

You'll need an IPinfo API access token, which you can get by signing up for a free account at https://ipinfo.io/signup.

The free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see https://ipinfo.io/pricing

You can find the full package level documentation here: https://pkg.go.dev/github.com/ipinfo/go/v2/ipinfo

Installation

go get github.com/ipinfo/go/v2/ipinfo

Quickstart

Basic usage of the package.

package main

import (
	"fmt"
	"log"
	"net"
	"github.com/ipinfo/go/v2/ipinfo"
)

func main() {
	const token = "YOUR_TOKEN"
	
	// params: httpClient, cache, token. `http.DefaultClient` and no cache will be used in case of `nil`.
	client := ipinfo.NewClient(nil, nil, token)

	const ip_address = "8.8.8.8"
	info, err := client.GetIPInfo(net.ParseIP(ip_address))

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(info)
	// Output: {8.8.8.8 dns.google false true Mountain View California US United States...
}

This data is available even on our free tier which includes upto 50,000 IP geolocation requests per month.

Authentication

The IPinfo Go library ca be authenticated with your IPinfo API access token, which is passed as the third positional argument of the ipinfo.NewClient() method. Your IPInfo access token can be found in the account section of IPinfo's website after you have signed in : https://ipinfo.io/account/token

const token = "YOUR_TOKEN"
// params: httpClient, cache, token. `http.DefaultClient` and no cache will be used in case of `nil`.
client := ipinfo.NewClient(nil, nil, token)

Internationalization

Country Name

info.Country returns the ISO 3166 country code and info.CountryName returns the entire conuntry name:

fmt.Println(info.Country)
// Output: US
fmt.Println(info.CountryName)
// Output: United States

European Union (EU) Country

info.IsEU returns a boolean response to see if a country is a Eurpoean Union country or not.

fmt.Println(info.IsEU)
// Output: false

Country Flag

Get country flag as an emoji and it's unicode value with info.CountryFlag.Emoji and info.CountryFlag.Unicode respectively.

fmt.Println(info.CountryFlag.Emoji)
// Output: 🇳🇿 
fmt.Println(info.CountryFlag.Unicode)
// Output: "U+1F1F3 U+1F1FF"

Country Currency

Get country's currency code and it's symbol with info.CountryCurrency.Code and info.CountryCurrency.Symbol respectively.

fmt.Println(info.CountryCurrency.Code)
// Output: USD 
fmt.Println(info.CountryCurrency.Symbol)
// Output: $

Continent

Get IP's continent code and it's name with info.Continent.Code and info.Continent.Name respectively.

fmt.Println(info.Continent.Code)
// Output: NA 
fmt.Println(info.Continent.Name)
// Output: North America

Map IP Address

You can map upto 500,000 IP address all at once using the GetIPMap command. You can input:

  • IP addresses (IPV4 and IPV6 both)
  • IP Ranges or Netblock
  • ASN

After the operation, you will be presented with a URL to a map generated on the IPinfo website.

IP Map Code:

package main

import (
	"fmt"
	"log"
	"net"

	"github.com/ipinfo/go/v2/ipinfo"
)

func main() {
	client := ipinfo.NewClient(nil, nil, "YOUR_TOKEN")
	result, err := client.GetIPMap(
		[]net.IP{
			net.ParseIP("136.111.157.61"),
			net.ParseIP("231.163.78.134"),
			// ...
			net.ParseIP("228.128.213.179"),
			net.ParseIP("103.172.175.76"),
		},
	)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result)
}

Result:

See the output example map: https://ipinfo.io/tools/map/f27c7d40-3ff0-4ac2-878f-8d953dbcd3c8

Summarize IP Address

Summarize IP addresses with GetIPSummary and output a report.

package main

import (
	"fmt"
	"log"
	"net"

	"github.com/ipinfo/go/v2/ipinfo"
)

func main() {
	client := ipinfo.NewClient(nil, nil, "YOUR_TOKEN")
	result, err := client.GetIPSummary(
		[]net.IP{
			net.ParseIP("171.164.236.38"),
			net.ParseIP("206.132.224.214"),
			// ....
			net.ParseIP("208.191.89.104"),
			net.ParseIP("81.216.14.76"),
		},
	)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result)
	// Ouptut: {100 100 map[CN:7 DE:4 JP:12 MX:3 US:32] map[Columbus, ...

}

Batch Operations / Bulk Lookup

You can do batch lookup or bulk lookup quite easily as well. The inputs supported:

  • IP addresses. IPV4 and IPV6 both
  • ASN
  • Specific field endpoint of an IP address e.g. 8.8.8.8/country
package main

import (
	"fmt"
	"log"
	"time"
	"github.com/ipinfo/go/v2/ipinfo"
	"github.com/ipinfo/go/v2/ipinfo/cache"
)

func main() {
	client := ipinfo.NewClient(
		nil,
		ipinfo.NewCache(cache.NewInMemory().WithExpiration(5*time.Minute)),
		"YOUR_TOKEN",
	)

	// batchResult will contain all the batch lookup data
	batchResult, err := client.GetBatch(
		[]string{
			"104.193.114.182",                    // you can pass IPV4 address
			"8.8.8.8/country",                    // you can get specific information
			"AS36811",                            // you can lookup ASN details
			"2a03:2880:f10a:83:face:b00c:0:25de", // IPV6 address
		},
		ipinfo.BatchReqOpts{
			BatchSize:       2,
			TimeoutPerBatch: 0,
			TimeoutTotal:    5,
		},
	)
	if err != nil {
		log.Fatal(err)
	}
	for k, v := range batchResult {
		fmt.Printf("k=%v v=%v\n", k, v)
	}
}

Examples of Batch / Bulk Lookup:

The loop declaration in the batch lookup are to showcase the "caching" capability of the IPinfo package.

Other Libraries

There are official IPinfo client libraries available for many languages including PHP, Python, Go, Java, Ruby, and many popular frameworks such as Django, Rails and Laravel. There are also many third party libraries and integrations available for our API.

About IPinfo

Founded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, VPN detection, hosted domains, and IP type data sets. Our API handles over 40 billion requests a month for 100,000 businesses and developers.

image

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].