The client IP (Internet Protocol) address remains one of the most valuable pieces of gatherable information used to identify a device on a local network or the Internet. An IP Address uses a number format such as 203.0.113.42 or 2001:0002:14:5:1:2:bf35:2610, with each number set within a range from 0 to 255. So, the full IP addressing range goes from 0.0.0.0 to 255.255.255.255. The numbers are not random and act as identifiers within the network or externally to websites and applications. 

Not all IP addresses are created equal

The basic rule of thumb is that an external IP Address is not yours, and indeed, if your IP address is Dynamic, then it can change as often as every time you reboot your router. However, if you have a Fixed / Static IP, it is reserved by your Network or ISP and assigned until a distinct change. For most users, this is preferable as it enables specific device access and a clean sheet away from less security-savvy or, indeed, unscrupulous/spammy users on the same dynamically assigned IP pool. However, if you transgress, it's easier to identify and punish a user with a fixed/static IP, so keep that in mind. And to be clear, you can't take an IP address with you on holiday or between ISPs as they are both location and ISP specific. 

Uses of an IP Address

Externally an IP Address can be used primarily to:-

  1. Reveal geolocation, but not a precise location, typically that of the ISP's nearest servers and Postcode/Area Code and ISP Name.
  2. Reveal a routers IP address, but not interconnected devices such as computers, tablets, mobile devices etc.
  3. Act as a signature to visited websites, including social media, online stores, forums, chatrooms and blogs. 

Knowing a user's geolocation, the number of times they visit a website, the types of websites they visit, the time and duration of the visit, and tagging those users as 'unique' offers valuable and measurable analytical information. Conversely, a user's IP address helps limit or ban a user from a website or application so an IP Address can address a range of positive and negative website behaviours. So now that we know some of the uses of gathering IP Addresses, here is how to get a users IP address via a website.

Get a user IP Address with jQuery and ipify API the simple public IP Address API

Use the following jQuery to establish a connection to ipify API to get a users IP address for output: -

How to use the obtained IP Address

In our example, we have 3 options for capturing the IP address:-

1.  Pass IP address value to a hidden field for form capture

2. Pass the output of the IP as text

3. Store the IP address in the Console log

Example displaying IP as Text in a Div

This example uses option 2, incorporating a div (#ip-text) and outputting the current IP into the div.

What is my IP Address?

This page will momentarily capture and output your IP address below: - 

Your IP Address is: Display IP Address

How will you use the Get IP Script?

Let us know your uses for capturing a users IP address, and don't forget to let your users know the purposes and possible storage of the data.