ProductPromotion
Logo

Node.JS

made by https://0x3d.site

GitHub - sindresorhus/public-ip: Get your public IP address - very fast!
Get your public IP address - very fast! Contribute to sindresorhus/public-ip development by creating an account on GitHub.
Visit Site

GitHub - sindresorhus/public-ip: Get your public IP address - very fast!

GitHub - sindresorhus/public-ip: Get your public IP address - very fast!

public-ip

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

import {publicIp, publicIpv4, publicIpv6} from 'public-ip';

console.log(await publicIp()); // Falls back to IPv4
//=> 'fe80::200:f8ff:fe21:67cf'

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

console.log(await publicIpv4());
//=> '46.5.21.123'

API

publicIp(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.

publicIpv6(options?)

Returns a Promise<string> with your public IPv6 address. Rejects on error or timeout.

A .cancel() method is available on the promise, which can be used to cancel the request.

publicIpv4(options?)

Returns a Promise<string> with your public IPv4 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 against 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.

import {publicIpv6} from 'public-ip';

await publicIpv6({
	fallbackUrls: [
		'https://ifconfig.co/ip'
	]
});
timeout

Type: number
Default: 5000

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

IpNotFoundError

Error thrown when the public IP address could not be found.

CancelError

Error thrown when the operation was canceled.

Maintainers

Related

Articles
to learn more about the nodejs concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about NodeJS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory