Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

public-ip

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

public-ip - npm Package Compare versions

Comparing version 5.0.0 to 6.0.0

core.js

25

browser.js

@@ -1,2 +0,3 @@

import isIp from 'is-ip';
import {isIPv6, isIPv4} from 'is-ip';
import {createPublicIp, IpNotFoundError} from './core.js';

@@ -14,8 +15,3 @@ export class CancelError extends Error {

export class IpNotFoundError extends Error {
constructor(options) {
super('Could not get the public IP address', options);
this.name = 'IpNotFoundError';
}
}
export {IpNotFoundError} from './core.js';

@@ -48,4 +44,5 @@ const defaults = {

const ip = xhr.responseText.trim();
const method = version === 'v6' ? isIPv6 : isIPv4;
if (!ip || !isIp[version](ip)) {
if (!ip || !method(ip)) {
reject();

@@ -105,8 +102,10 @@ return;

const publicIp = {};
export const publicIp = createPublicIp(publicIpv4, publicIpv6);
publicIp.v4 = options => queryHttps('v4', {...defaults, ...options});
export function publicIpv4(options) {
return queryHttps('v4', {...defaults, ...options});
}
publicIp.v6 = options => queryHttps('v6', {...defaults, ...options});
export default publicIp;
export function publicIpv6(options) {
return queryHttps('v6', {...defaults, ...options});
}

@@ -32,5 +32,5 @@ /**

```
import publicIp from 'public-ip';
import {publicIpv6} from 'public-ip';
await publicIp.v6({
await publicIpv6({
fallbackUrls: [

@@ -49,42 +49,56 @@ 'https://ifconfig.co/ip'

declare const publicIp: {
/**
Get your public IP address - very fast!
/**
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](https://github.com/major/icanhaz) and [ipify](https://ipify.org) services through HTTPS.
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](https://github.com/major/icanhaz) and [ipify](https://ipify.org) services through HTTPS.
@returns Your public IPv4 address. A `.cancel()` method is available on the promise, which can be used to cancel the request.
@throws On error or timeout.
@returns Your public IPv6 address or as a fallback, your public IPv4 address. A `.cancel()` method is available on the promise, which can be used to cancel the request.
@throws On error or timeout.
@example
```
import publicIp from 'public-ip';
@example
```
import {publicIp} from 'public-ip';
console.log(await publicIp.v4());
//=> '46.5.21.123'
```
*/
v4(options?: Options): CancelablePromise<string>;
console.log(await publicIp()); // Falls back to IPv4
//=> 'fe80::200:f8ff:fe21:67cf'
```
*/
export function publicIp(options?: Options): CancelablePromise<string>;
/**
Get your public IP address - very fast!
/**
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](https://github.com/major/icanhaz) and [ipify](https://ipify.org) services through HTTPS.
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](https://github.com/major/icanhaz) and [ipify](https://ipify.org) services through HTTPS.
@returns Your public IPv6 address. A `.cancel()` method is available on the promise, which can be used to cancel the request.
@throws On error or timeout.
@returns Your public IPv4 address. A `.cancel()` method is available on the promise, which can be used to cancel the request.
@throws On error or timeout.
@example
```
import publicIp from 'public-ip';
@example
```
import {publicIpv4} from 'public-ip';
console.log(await publicIp.v6());
//=> 'fe80::200:f8ff:fe21:67cf'
```
*/
v6(options?: Options): CancelablePromise<string>;
};
console.log(await publicIpv4());
//=> '46.5.21.123'
```
*/
export function publicIpv4(options?: Options): CancelablePromise<string>;
export default publicIp;
/**
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](https://github.com/major/icanhaz) and [ipify](https://ipify.org) services through HTTPS.
@returns Your public IPv6 address. A `.cancel()` method is available on the promise, which can be used to cancel the request.
@throws On error or timeout.
@example
```
import {publicIpv6} from 'public-ip';
console.log(await publicIpv6());
//=> 'fe80::200:f8ff:fe21:67cf'
```
*/
export function publicIpv6(options?: Options): CancelablePromise<string>;
export {CancelError} from 'got';

@@ -5,10 +5,6 @@ import {promisify} from 'node:util';

import got, {CancelError} from 'got';
import isIp from 'is-ip';
import {isIPv6, isIPv4} from 'is-ip';
import {createPublicIp, IpNotFoundError} from './core.js';
export class IpNotFoundError extends Error {
constructor(options) {
super('Could not get the public IP address', options);
this.name = 'IpNotFoundError';
}
}
export {IpNotFoundError} from './core.js';

@@ -128,3 +124,5 @@ const defaults = {

if (ip && isIp[version](ip)) {
const method = version === 'v6' ? isIPv6 : isIPv4;
if (ip && method(ip)) {
socket.destroy();

@@ -183,3 +181,5 @@ return ip;

if (ip && isIp[version](ip)) {
const method = version === 'v6' ? isIPv6 : isIPv4;
if (ip && method(ip)) {
return ip;

@@ -234,5 +234,5 @@ }

const publicIp = {};
export const publicIp = createPublicIp(publicIpv4, publicIpv6);
publicIp.v4 = options => {
export function publicIpv4(options) {
options = {

@@ -252,5 +252,5 @@ ...defaults,

return queryDns('v4', options);
};
}
publicIp.v6 = options => {
export function publicIpv6(options) {
options = {

@@ -270,6 +270,4 @@ ...defaults,

return queryDns('v6', options);
};
}
export default publicIp;
export {CancelError} from 'got';
{
"name": "public-ip",
"version": "5.0.0",
"version": "6.0.0",
"description": "Get your public IP address — very fast!",

@@ -15,2 +15,3 @@ "license": "MIT",

"exports": {
"types": "./index.js",
"node": "./index.js",

@@ -20,3 +21,3 @@ "default": "./browser.js"

"engines": {
"node": "^14.13.1 || >=16.0.0"
"node": ">=14.16"
},

@@ -30,3 +31,3 @@ "scripts": {

"browser.js",
"browser.d.ts"
"core.js"
],

@@ -47,11 +48,13 @@ "keywords": [

"dependencies": {
"aggregate-error": "^4.0.1",
"dns-socket": "^4.2.2",
"got": "^12.0.0",
"is-ip": "^3.1.0"
"got": "^12.1.0",
"is-ip": "^4.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"sinon": "^12.0.1",
"tsd": "^0.19.0",
"xo": "^0.47.0"
"ava": "^4.3.0",
"sinon": "^14.0.0",
"time-span": "^5.0.0",
"tsd": "^0.21.0",
"xo": "^0.50.0"
},

@@ -58,0 +61,0 @@ "xo": {

@@ -16,9 +16,12 @@ # public-ip

```js
import publicIp from 'public-ip';
import {publicIp, publicIpv4, publicIpv6} from 'public-ip';
console.log(await publicIp.v4());
//=> '46.5.21.123'
console.log(await publicIp()); // Falls back to IPv4
//=> 'fe80::200:f8ff:fe21:67cf'
console.log(await publicIp.v6());
console.log(await publicIpv6());
//=> 'fe80::200:f8ff:fe21:67cf'
console.log(await publicIpv4());
//=> '46.5.21.123'
```

@@ -28,7 +31,20 @@

### publicIp.v4(options?)
### publicIp.v6(options?)
### 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.
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

@@ -53,5 +69,5 @@

```js
import publicIp from 'public-ip';
import {publicIpv6} from 'public-ip';
await publicIp.v6({
await publicIpv6({
fallbackUrls: [

@@ -58,0 +74,0 @@ 'https://ifconfig.co/ip'

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc