/ IPinfo

Detailed Guide to Geographic Targeting and Personalization using IPinfo.io

01 - What is IPInfo.io?

Let's look at what this wonderful service called ipinfo.io is. As the webpage, says IPinfo is one of the most trusted sources of information based on IP address data. This is actually extremely useful, and I have personally tested the service. The information provided by IPinfo based on the IP address of the user is extremely accurate and very useful for various businesses. For instance, as you can see on this page. I am accessing IPInfo using my current IP address of my current location and the information that has been provided is extremely close to, to the physical reality of my location.

It is about 25 kilometers apart, I've tested the details on Google Maps and the error between my current location and the location which is being imputed from my IP address is about 25 kilometers. I think that is pretty negligible. at the scale of the Internet, and this information is particularly useful
to businesses, which I will cover in further down this document.

02 - IPInfo usage and support for various programming languages

Now that we have a fair idea about IPinfo, let's get our hands dirty and start using the service. IPinfo comes with a free tier that is very useful. The amount of information provided to a free user is amazing.

So first, the service is pretty much a REST based service. The data that's provided by the service can be accessed using typical REST calls which are extremely popular nowadays. IPinfo primarily uses JSON as a data transport format.

As many of the viewers or readers of the document will already know. REST calls are well supported in pretty much all the languages. IPinfo, right out of the box, provides support for very popular languages including PHP, Python, Perl, Java, Ruby, etc as their official libraries. A quick search on GitHub also provides access to using other languages. Given the nature of the service architecture, most of the code available is pretty accessible and reliable.

IPinfo designed to make it easy to use, simple and fast to be productive

03 - IPinfo - Authorization Procedure

One of the first steps to access the IPinfo service is to authorize your request. IPinfo has done a pretty good job of documenting the process for authentication, issuing requests and processing responses on their web page.

I will expand on this further in the document and hopefully it will be of use to users. Should you have any questions please feel free to drop in an email or a comment and I'll do my best to respond to it.

Like I mentioned earlier, IPinfo supports various standard languages. Being a programmer myself and having a very strong preference to keep things simple and neat I prefer the terminal based approach.

Usage on the terminal is pretty much like many other applications. I tend to use curl to access data across internet.

The first step to authorize a request to IP info is using the token. The token is available on the dashboard.

I highly recommend to keep the token private as that is unique for every logged in user be free, or be paid.

It's information that should not be distributed for public usage.

On the terminal, we will use our token as the access authorization parameter, before we issue calls to IPinfo.

Store tokens in a private .env file

I prefer to use the to the procedure of using an authorization header. However, on review of the various functionalities provided by IPinfo. I feel that for this particular service, it is best to be using the access token as part of the URL parameter.

Bear in mind, do not disclose the token publicly. I will explain the process of invoking an environment file, which is private to a particular machine. By invoking the environment file, we can set the token automatically in the terminal session.

Since we made us be using the URL based approach, once we invoke the environment file. We no longer need to set the token at any point, the token will be picked up from the environment, and calls to IPinfo will be issued.

04 - IPinfo - Authorization Demo

In this section we will look at the demonstration of authorizing the terminal calls, using the environment file.

Keep .env private.

An example of the .env file is:

TOKEN="EnterYourToken"

Invoke this file using:

source .env

Store tokens in a private .env file

05 - IP Info - Information Request Demo

Let's get our hands dirty and actually issue the calls using the environment variable we've set for the terminal.

I'll show a live demonstration of the services that are accessible with a free free user account and also a paid account.

The steps are as follows:

bash

# set the environment variables
source ./shell/.ipinfo.env

# get basic ip address request
curl ipinfo.io?token=$TOKEN | jq


# full response. need pro plan
# documented at [API Responses - IPinfo.io](https://ipinfo.io/developers/responses#full-response)
cat full.json | jq

After invoking the environment variables which setup the authorization token, we get the info for our own IP address.

curl ipinfo.io?token=$TOKEN | jq

The output of the call to this service endpoint is shown below.

ipinfo-own-ip

It includes rich data points include:

  • current IP address
  • location
  • region
  • location coordinates (latitude and longitude)
  • the organization that my system is being serviced from
  • postal code of my location and
  • time zone I am in.

Depending on the authorization token subscription level which includes, a pro package, an enterprise package, and a free or basic package, there are various sets of information returned on your calls.

The full response is the most detailed response. You could invoke portions of these responses directly from IPinfo (which is faster) or you could process the data using jq.

The full response needs a pro plan and return a lot of rich data as shown below.

{
  "ip": "157.230.145.153",
  "city": "Santa Clara",
  "region": "California",
  "country": "US",
  "loc": "37.3483,-121.9844",
  "postal": "95051",
  "timezone": "America/Los_Angeles",
  "asn": {
    "asn": "AS14061",
    "name": "DigitalOcean, LLC",
    "domain": "digitalocean.com",
    "route": "157.230.144.0/20",
    "type": "hosting"
  },
  "hosting": {
    "host": "digitalocean",
    "id": "DO-13",
    "name": "DigitalOcean, LLC",
    "network": "157.230.0.0/16"
  },
  "company": {
    "name": "DigitalOcean, LLC",
    "domain": "digitalocean.com",
    "type": "hosting"
  },
  "abuse": {
    "address": "US, NY, New York, 101, Ave of the Americas, 10013",
    "country": "US",
    "email": "[email protected]",
    "name": "DigitalOcean Abuse",
    "network": "157.230.0.0/16",
    "phone": "+1-347-875-6044"
  }
}

As shown, in addition to the getting the basic information, the ASN info, the hosting info, the company servicing my connection and details related to my carrier are included.

06 - ASN Information Request Demo

Let's look at a couple of other API functionalities and provided by IPinfo.

They work in similar fashion, except that the URLs for each of those services changes depending on the function. So do the parameters that need to be passed to the call.

The basic setup of having the authorization with the token party has to remain the same. And the information gets returned based on the particular call that's getting made.

In this video, we will look at the ASN API. Lot of details on ASN Info is availble on Wikipedia. ANS (autonomous system number) info provides a lot of information related to the ISP provider.

API info is accessible only on the standard of pro plan

On issuing the below request, we will get a very rich data related to the provider, including the assigned prefixes, the related domains and a lot more.

# ASP API. need pro plan
# documented at https://ipinfo.io/developers/asn
# read more at [Autonomous system (Internet) - Wikipedia](https://en.wikipedia.org/wiki/Autonomous_system_(Internet))
# DO NOT RUN - curl ipinfo.io/AS14061/json?token=$TOKEN

API Info is very rich!

For example, the digitalocean output is shown below. It has close to 2.1 million IPS registered with it! It has a various set of prefixes a lot upstream data and downstream data. A total of ~ 5000 rows related to just one ASN!

ipinfo-asninfo-AS14061-DigitalOcean--LLC

That's extremely rich information and very useful for various purposes. We will look at business use cases further down!

07 - IP Info - Other Information Requests Demo

IPinfo has a few more endpoint calls similar to above requests.

The IP ranges API, which basically will return all the IP addresses operated by a company assigned to or operated by a company.

This simple call, which will function very similar to the earlier calls and return ip ranges assigned to comcast.net.

curl ipinfo.io/ranges/comcast.net?token=$TOKEN

ipinfo-ip-ranges-api

Here's a very fun topic! Hosted domains!

A call to the hosted domains api endpoint gives you the list of all domains that are serviced by that provider.

curl ipinfo.io/domains/comcast.net?token=$TOKEN

ipinfo-hosted-domains-api

We can also get details about the total number of domains hosted on an ASN or IP address range associated with the IP address or domain.

curl ipinfo.io/domains/69.240.0.0/12?token=$TOKEN

# ip ranges on an ASN
curl ipinfo.io/domains/AS7922?token=$TOKEN

08 - IP Info - Business Use Case - Tesla Motors

Now that we've got a good sense of the rich service that is provided by IPinfo, let us look at how to make money, how to put into use and how to do something useful!

In order to demonstrate this, I will be showing two examples, one is a business application using our Tesla the famous electrical vehicle company founded by Mr. Elon Musk.

The next will be a visualization project which is data science oriented it can help a lot in journalism, etc.

So first things first, let's look at the Tesla example!

A quick visit to tesla.com with Chrome Dev Tools is shown in the video below.

One of the first network calls issued by tesla.com is a request related to location of the user based on the IP address.

With this simple call, Tesla is getting a lot of information about me. Tesla is able to learn about my geography, loation, provider, etc. This is all extremely valuable information!

ipinfo-tesla-geoinfo-call

Now, let us understand how this information can be put to use.

First, Tesla has information related to my location without really prompting me with the annoying message to share my location explicitly using the browser functionality.

Second, Tesla is now able to get a sense about where its customers are visiting from which is in itself an extremely valuable data point.

Third, based on this new info about my visit, Tesla can customize the website that is being served to any particularly user using this information.

For instance, they would recognize that currently I am in the in Duluth and and they can immediately send me an offer from stores in Duluth or increase notifications on promotions or events happening in Duluth.

Now, that can significantly increase my propensity to engage in further conversation leading to very rewarding business with Tesla.

Similarly, this data is extremely useful not just for high ticket purchases. The utility of such location based information can be used by shopping websites like eBay or Walmart, and fashion websites like Macy's and what have you!

I hope that gives you a good sense about the valuable information that is being provided by IPinfo to help improve customer and business value!

Drop me a note on thoughts and comments! :-)