public-ip
Get your public IP address - very fast!
Last updated 3 months ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install public-ip 
SYNC missed versions from official npm registry.

public-ip Build Status

Get your public IP address - very fast!

In Node.js, it queries the DNS records of OpenDNS, Google DNS, and HTTPS services to determine your IP address. In browsers, it uses the excellent icanhaz and ipify services through HTTPS.

Install

$ npm install public-ip

Usage

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

(async () => {
	console.log(await publicIp.v4());
	//=> '46.5.21.123'

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

API

publicIp.v4(options?)

publicIp.v6(options?)

Returns a Promise<string> with your public IPv4 or IPv6 address. Rejects on error or timeout. A .cancel() method is available on the promise, which can be used to cancel the request.

options

Type: object

onlyHttps

Type: boolean
Default: false

Use a HTTPS check using the icanhazip.com service instead of the DNS query. ipify.org is used as a fallback if icanhazip.com fails. This check is much more secure and tamper-proof, but also a lot slower. This option is only available in the Node.js version. The default behaviour is to check aginst DNS before using HTTPS fallback. If set to true, it will only check against HTTPS.

fallbackUrls

Type: string[]
Default: []

Add your own custom HTTPS endpoints to get the public IP from. They will only be used if everything else fails. Any service used as fallback must return the IP as a plain string.

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

(async () => {
	await publicIp.v6({
		fallbackUrls: [
			'https://ifconfig.co/ip'
		]
	});
})();
timeout

Type: number
Default: 5000

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

Maintainers

Related

Current Tags

  • 4.0.1                                ...           latest (3 months ago)

25 Versions

  • 4.0.1                                ...           3 months ago
  • 4.0.0                                ...           7 months ago
  • 3.2.0                                ...           a year ago
  • 3.1.0                                ...           a year ago
  • 3.0.0                                ...           2 years ago
  • 2.5.0                                ...           2 years ago
  • 2.4.0                                ...           3 years ago
  • 2.3.5                                ...           3 years ago
  • 2.3.4                                ...           3 years ago
  • 2.3.3                                ...           3 years ago
  • 2.3.2                                ...           3 years ago
  • 2.3.1                                ...           3 years ago
  • 2.3.0                                ...           3 years ago
  • 2.2.1                                ...           3 years ago
  • 2.2.0                                ...           3 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.1                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
Downloads
Today 39
This Week 161
This Month 74
Last Day 35
Last Week 184
Last Month 893
Dependencies (3)
Dev Dependencies (4)
Dependents (253)

Copyright 2014 - 2016 © taobao.org |