{"id":13453613,"url":"https://github.com/sindresorhus/public-ip","last_synced_at":"2025-05-14T15:06:25.564Z","repository":{"id":20750100,"uuid":"24034567","full_name":"sindresorhus/public-ip","owner":"sindresorhus","description":"Get your public IP address - very fast!","archived":false,"fork":false,"pushed_at":"2024-07-26T15:03:05.000Z","size":91,"stargazers_count":1038,"open_issues_count":3,"forks_count":66,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-05-07T09:27:54.595Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2014-09-14T22:02:04.000Z","updated_at":"2025-04-29T05:56:37.000Z","dependencies_parsed_at":"2024-04-11T14:29:09.251Z","dependency_job_id":"84642e3f-590e-480a-928c-751af7ab61f8","html_url":"https://github.com/sindresorhus/public-ip","commit_stats":{"total_commits":101,"total_committers":15,"mean_commits":6.733333333333333,"dds":0.4158415841584159,"last_synced_commit":"7ebf3395006bf42954f08d514edbb6732c083e4a"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpublic-ip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpublic-ip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpublic-ip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpublic-ip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/public-ip/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254169062,"owners_count":22026208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:00:44.345Z","updated_at":"2025-05-14T15:06:25.516Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript","Packages","Repository","包","目录","Fingerprint","Uncategorized","others","Command-line apps","\u003ca id=\"9eee96404f868f372a6cbc6769ccb7f8\"\u003e\u003c/a\u003e工具"],"sub_categories":["Command-line apps","Network","命令行程序","命令行应用","IP","Uncategorized","\u003ca id=\"31185b925d5152c7469b963809ceb22d\"\u003e\u003c/a\u003e新添加的"],"readme":"# public-ip\n\n\u003e 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 excellent [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()); // Falls back to IPv4\n//=\u003e 'fe80::200:f8ff:fe21:67cf'\n\nconsole.log(await publicIpv6());\n//=\u003e 'fe80::200:f8ff:fe21:67cf'\n\nconsole.log(await publicIpv4());\n//=\u003e '46.5.21.123'\n```\n\n## API\n\n### publicIp(options?)\n\nReturns a `Promise\u003cstring\u003e` with your public IPv4 or IPv6 address. Rejects on error or timeout.\n\nA `.cancel()` method is available on the promise, which can be used to cancel the request.\n\n### publicIpv6(options?)\n\nReturns a `Promise\u003cstring\u003e` with your public IPv6 address. Rejects on error or timeout.\n\nA `.cancel()` method is available on the promise, which can be used to cancel the request.\n\n### publicIpv4(options?)\n\nReturns a `Promise\u003cstring\u003e` with your public IPv4 address. Rejects on error or timeout.\n\nA `.cancel()` method is available on the promise, which can be used to cancel the request.\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://www.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 a request is considered timed out.\n\n### IpNotFoundError\n\nError thrown when the public IP address could not be found.\n\n### CancelError\n\nError thrown when the operation was canceled.\n\n## Maintainers\n\n- [Sindre Sorhus](https://github.com/sindresorhus)\n- [silverwind](https://github.com/silverwind)\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fpublic-ip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fpublic-ip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fpublic-ip/lists"}