GithubHelp home page GithubHelp logo

public-ip's Introduction

public-ip Build Status

Get your public IP address - very fast!

In Node.js, it queries the DNS records of OpenDNS which has an entry with your IP address.

In browsers, it uses the excellent icanhaz service through HTTPS.

Install

$ npm install --save public-ip

Usage

const publicIp = require('public-ip');

publicIp.v4().then(ip => {
	console.log(ip);
	//=> '46.5.21.123'
});

publicIp.v6().then(ip => {
	console.log(ip);
	//=> 'fe80::200:f8ff:fe21:67cf'
});

API

publicIp.v4([options])

publicIp.v6([options])

Returns a Promise which resolves to your public IPv4 or IPv6 address. Will reject on error or timeout. A .cancel() method is available on the promise, which can be used to cancel the request.

options

Type: Object

https

Type: boolean
Default: false

Use a HTTPS check using the icanhazip.com service instead of the DNS query. This check is much more secure and tamper-proof, but also a lot slower. This option is only available in the Node.js version.

timeout

Type: number
Default: 5000

The time in milliseconds until a request is considered timed out.

Maintainers

Related

License

MIT © Sindre Sorhus

public-ip's People

Contributors

sindresorhus avatar silverwind avatar arthurvr avatar kevva avatar marsup avatar samverschueren avatar

Watchers

James Cloos 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.