{"name":"public-ip","version":"8.0.0","description":"Get your public IP address — very fast!","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/public-ip.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./source/index.d.ts","node":"./source/index.js","default":"./source/browser.js"},"sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && node --test test-node.js && tsc source/index.d.ts --skipLibCheck"},"keywords":["get","ip","ipv4","ipv6","address","external","public","machine","fast","opendns","dns"],"dependencies":{"dns-socket":"^4.2.2","is-ip":"^5.0.1"},"devDependencies":{"@sindresorhus/tsconfig":"^8.0.1","typescript":"^5.9.2","xo":"^1.2.2"},"_id":"public-ip@8.0.0","gitHead":"3592f29bb3233a95961aad8ed4910ea5b5d85608","bugs":{"url":"https://github.com/sindresorhus/public-ip/issues"},"homepage":"https://github.com/sindresorhus/public-ip#readme","_nodeVersion":"20.19.5","_npmVersion":"10.9.2","dist":{"integrity":"sha512-XzVyz98rNQiTRciAC+I4w45fWWxM9KKedDGNtH4unPwBcWo2Y9n7kgPXqlTiWqKN0EFlIIU1i8yrWOy9mxgZ8g==","shasum":"e97034b62a24c754ec9752857db8a7cfd67c7590","tarball":"http://registry-npm.ywwl.com/public-ip/download/public-ip-8.0.0.tgz","fileCount":14,"unpackedSize":17512,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD9tyzryRzYq4Un0XYmFvhyX/Mj/v6fWQ6odszF+2SgOQIgSk51Hy5Hi/NpT3sl4KEhOmYXIzAWppv1JgaxVpEd/+U="}],"size":5215,"noattachment":false,"key":"/public-ip/-/public-ip-8.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/public-ip_8.0.0_1758460558124_0.6730176201363134"},"_hasShrinkwrap":false,"readme":"# public-ip\n\n> Get your public IP address - very fast!\n\nIn Node.js, it queries the DNS records of OpenDNS, Google DNS, and HTTPS services to determine your IP address. In browsers, it uses the [icanhaz](https://github.com/major/icanhaz) and [ipify](https://ipify.org) services through HTTPS.\n\n## Install\n\n```sh\nnpm install public-ip\n```\n\n## Usage\n\n```js\nimport {publicIp, publicIpv4, publicIpv6} from 'public-ip';\n\nconsole.log(await publicIp()); // Tries IPv6 first, falls back to IPv4\n//=> 'fe80::200:f8ff:fe21:67cf'\n\nconsole.log(await publicIpv6());\n//=> 'fe80::200:f8ff:fe21:67cf'\n\nconsole.log(await publicIpv4());\n//=> '46.5.21.123'\n```\n\n## API\n\n### publicIp(options?)\n\nReturns a `Promise<string>` with your public IPv4 or IPv6 address. Tries IPv6 first, then falls back to IPv4. Rejects on error or timeout.\n\n### publicIpv4(options?)\n\nReturns a `Promise<string>` with your public IPv4 address. Rejects on error or timeout.\n\n### publicIpv6(options?)\n\nReturns a `Promise<string>` with your public IPv6 address. Rejects on error or timeout.\n\n#### options\n\nType: `object`\n\n##### onlyHttps\n\nType: `boolean`\\\nDefault: `false`\n\nUse a HTTPS check using the [icanhazip.com](https://github.com/major/icanhaz) service instead of the DNS query. [ipify.org](https://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.\n\n##### fallbackUrls\n\nType: `string[]`\\\nDefault: `[]`\n\nAdd 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.\n\n```js\nimport {publicIpv6} from 'public-ip';\n\nawait publicIpv6({\n\tfallbackUrls: [\n\t\t'https://ifconfig.co/ip'\n\t]\n});\n```\n\n##### timeout\n\nType: `number`\\\nDefault: `5000`\n\nThe time in milliseconds until the operation is considered timed out. This applies to the entire operation, not individual requests.\n\n##### signal\n\nType: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\nAn `AbortSignal` to cancel the operation. If both `timeout` and `signal` are provided, the operation will be aborted when either the timeout is reached or the signal is aborted.\n\n### Error Handling\n\n```js\nimport {publicIpv4, IpNotFoundError} from 'public-ip';\n\ntry {\n\tconst ip = await publicIpv4({timeout: 5000});\n\tconsole.log(ip);\n} catch (error) {\n\tif (error instanceof IpNotFoundError) {\n\t\tconsole.log('Could not determine public IP address');\n\t} else if (error.message.includes('aborted')) {\n\t\tconsole.log('Request was cancelled');\n\t} else {\n\t\tconsole.log('An error occurred:', error.message);\n\t}\n}\n```\n\n### IpNotFoundError\n\nError thrown when the public IP address could not be found.\n\n## Related\n\n- [public-ip-cli](https://github.com/sindresorhus/public-ip-cli) - CLI for this module\n- [internal-ip](https://github.com/sindresorhus/internal-ip) - Get your internal IP address\n","publish_time":1758460558327,"_cnpm_publish_time":1758460558327,"dist-tags":{"latest":"8.0.0"}}