Skip to content

ip-loc gives IP Geolocation information for every IPv4 or IPv6 address

Notifications You must be signed in to change notification settings

ipapi-is/ip_to_location

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IP to Location

Npm package version Npm package yearly downloads

The npm package location-from-ip gives IP Geolocation information for every IPv4 or IPv6 address.

Currently, there are millions of different geolocation records in the database. Learn more, by reading the documentation.

Installation

You can both use this package from Node.js and in the browser with vanilla JavaScript.

npm install location-from-ip

If you want to clone the repository directly from GitHub instead:

git clone [email protected]:ipapi-is/ip_to_location.git

Usage from Node.js

If you want to lookup the IP address 144.168.164.55:

const { ipToGeolocation } = require('location-from-ip');

const ipAddresses = [
  '144.168.164.55',
  '167.99.241.66',
  '97.107.129.77',
  '85.10.199.76',
];

for (let ip of ipAddresses) {
  ipToGeolocation(ip).then(function (location) {
    console.log(`${ip} geolocation:`);
    console.log(location);
  });
}

which yields:

167.99.241.66 geolocation:
{
  continent: 'EU',
  country: 'Germany',
  country_code: 'DE',
  state: 'Hesse',
  city: 'Frankfurt am Main',
  latitude: 50.1109,
  longitude: 8.68213,
  zip: '07022',
  timezone: 'Europe/Berlin',
  local_time: '2023-10-22T13:36:01+02:00',
  local_time_unix: 1697974561,
  is_dst: true
}
85.10.199.76 geolocation:
{
  continent: 'EU',
  country: 'Germany',
  country_code: 'DE',
  state: 'Bavaria',
  city: 'Nürnberg',
  latitude: 49.45421,
  longitude: 11.07752,
  zip: '90403',
  timezone: 'Europe/Berlin',
  local_time: '2023-10-22T13:36:01+02:00',
  local_time_unix: 1697974561,
  is_dst: true
}
97.107.129.77 geolocation:
{
  continent: 'NA',
  country: 'United States',
  country_code: 'US',
  state: 'New Jersey',
  city: 'Morris Plains',
  latitude: 40.82177,
  longitude: -74.48099,
  zip: '07927',
  timezone: 'America/New_York',
  local_time: '2023-10-22T07:36:01-04:00',
  local_time_unix: 1697974561,
  is_dst: true
}
144.168.164.55 geolocation:
{
  continent: 'NA',
  country: 'Canada',
  country_code: 'CA',
  state: 'Quebec',
  city: "Baie-D'Urfé",
  latitude: 45.41397,
  longitude: -73.91586,
  zip: 'H9X',
  timezone: 'America/Toronto',
  local_time: '2023-10-22T07:36:01-04:00',
  local_time_unix: 1697974561,
  is_dst: true
}

Usage from the Browser

Copy the browser JavaScript bundle to your preferred location. After installing the module with

npm install location-from-ip

you can find the minified JavaScript here: node_modules/location-from-ip/dist/ipToGeolocation.min.js

<!doctype html>

<html lang="en">

<head>
  <meta charset="utf-8">
  <title>IP to Geolocation Example in Browser</title>
  <meta name="description" content="IP to Geolocation Example">
  <meta name="author" content="ipapi.is">
</head>

<body>
  <pre id="location"></pre>
  <script type="text/javascript" src="dist/ipToGeolocation.min.js"></script>
  <script type="text/javascript">
    ipToGeolocation('43.33.44.11').then((res) => {
      document.getElementById('location').innerText = JSON.stringify(res, null, 2);
    });
  </script>
</body>

</html>

Use the Database Directly

This package uses the ipapi.is geolocation database in order to avoid shipping a huge database in the npm module. If you have a large volume of IP addresses to lookup, you can download the full & free Geolocation Database.

GitHub mirror of the database: Geolocation Database

About

ip-loc gives IP Geolocation information for every IPv4 or IPv6 address

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published