Coder Social home page Coder Social logo

linkvn / iplocation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from richienb/iplocation

0.0 2.0 0.0 104 KB

get IP location information using various providers

Home Page: https://www.npmjs.org/package/iplocation

License: MIT License

TypeScript 38.09% JavaScript 61.91%

iplocation's Introduction

iplocation

NPM version Build status License

Get IP location information using various providers. ES module/Typescript support.

Installation

$ npm install --save iplocation

Usage

Importing:

CommonJS:

const iplocation = require("iplocation").default;

Breaking change (>= v6.0.0): .default is now required when using CommonJS require.

ES modules/Typescript:

import iplocation from "iplocation";

Callback: iplocation(ip, providers, callback)

Promise: iplocation(ip, [providers])

Providers:

Supply additional providers in the following format:

https://domain-name.tld/json/*
https://domain-name.tld/*/json
https://domain-name.tld/?ip=*&format=json

Basically wherever the API requires the IP address put a * and the module will replace it with the IP address entered as arguments.

You can omit the IP address parameter to return data for the ip address of the requesting client, (in a server environment this will be the server public IP address, in a browser this will be the clients public IP address).

Providers:

This module will try providers in order, moving onto then next provider if the request fails. If provided, additional providers will be tried first, if the all additional providers fail or none are provided then the hardcoded defaults are tried in order. You won't get anything if all providers fail.

Callback:

const iplocation = require("iplocation").default;

iplocation('56.70.97.8', [], (error, res) => {

    /* res:

        {
            as: 'AS11286 KeyBank National Association',
            city: 'Cleveland',
            country: 'United States',
            countryCode: 'US',
            isp: 'KeyBank National Association',
            lat: 41.4875,
            lon: -81.6724,
            org: 'KeyBank National Association',
            query: '156.77.54.32',
            region: 'OH',
            regionName: 'Ohio',
            status: 'success',
            timezone: 'America/New_York',
            zip: '44115'
        }

    */

});

Breaking change (>= v6.0.0): the additional providers array (even if empty) is required.

Promise:

const iplocation = require("iplocation").default;

iplocation("56.70.97.8")
    .then((res) => {
    })
    .catch(err => {
    });

See Also

iplocation-cli - this module as a command line app.

iplocation's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.