{"id":19686660,"url":"https://github.com/tinovyatkin/is-localhost-ip","last_synced_at":"2026-01-19T01:06:54.144Z","repository":{"id":35068320,"uuid":"202935213","full_name":"tinovyatkin/is-localhost-ip","owner":"tinovyatkin","description":"Checks whether given host/DNS name or IPv4/IPv6 address belongs to the local machine","archived":false,"fork":false,"pushed_at":"2023-11-07T23:34:00.000Z","size":1492,"stargazers_count":24,"open_issues_count":7,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-16T04:24:36.825Z","etag":null,"topics":["ipv4","ipv6","localhost","networking","nodejs"],"latest_commit_sha":null,"homepage":"","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/tinovyatkin.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-17T22:04:34.000Z","updated_at":"2025-04-14T15:35:57.000Z","dependencies_parsed_at":"2023-11-08T05:44:39.183Z","dependency_job_id":"2d7b7c02-bbb8-4167-8ff9-392a0aef8916","html_url":"https://github.com/tinovyatkin/is-localhost-ip","commit_stats":{"total_commits":295,"total_committers":7,"mean_commits":"42.142857142857146","dds":0.2779661016949152,"last_synced_commit":"51dd60cb01d3a0c444a05e00634ad3d38234cc61"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinovyatkin%2Fis-localhost-ip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinovyatkin%2Fis-localhost-ip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinovyatkin%2Fis-localhost-ip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinovyatkin%2Fis-localhost-ip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinovyatkin","download_url":"https://codeload.github.com/tinovyatkin/is-localhost-ip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251450656,"owners_count":21591407,"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":["ipv4","ipv6","localhost","networking","nodejs"],"created_at":"2024-11-11T18:29:42.029Z","updated_at":"2026-01-19T01:06:54.138Z","avatar_url":"https://github.com/tinovyatkin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![codecov](https://codecov.io/gh/tinovyatkin/is-localhost-ip/branch/master/graph/badge.svg)](https://codecov.io/gh/tinovyatkin/is-localhost-ip)\n![node](https://img.shields.io/node/v/is-localhost-ip)\n\n# is-localhost-ip\n\nZero-dependency Node.js utility that checks whether a hostname or IPv4/IPv6 address refers to the local machine.\n\nThis package aims to be strict and comprehensive:\n\n- Validates input as an IP address or a syntactically valid hostname (including bracketed IPv6).\n- Treats private/loopback/link-local ranges as local.\n- Optionally verifies the address exists on the current machine by attempting to bind to it.\n- Falls back to DNS resolution, so it works with hostnames mapped in `/etc/hosts` or a local resolver.\n\n## Installation\n\n```sh\nnpm i is-localhost-ip\n# or\nyarn add is-localhost-ip\n# or\npnpm add is-localhost-ip\n```\n\nRequires Node.js `\u003e=18`.\n\n## Usage\n\n```js\nconst isLocalhost = require(\"is-localhost-ip\");\n\n(async () =\u003e {\n  await isLocalhost(\"127.0.0.1\"); // true\n  await isLocalhost(\"::ffff:127.0.0.1\"); // true\n  await isLocalhost(\"192.168.0.12\"); // true\n  await isLocalhost(\"192.168.0.12\", true); // true only if an interface has this address\n  await isLocalhost(\"184.55.123.2\"); // false\n\n  await isLocalhost(\"tino.local\"); // true if it resolves to a local address\n  await isLocalhost(\"localhost\"); // true\n  await isLocalhost(\"microsoft.com\"); // false\n})();\n```\n\n## API\n\n### `isLocalhost(ipOrHostname, canBind?)`\n\nReturns a `Promise\u003cboolean\u003e`.\n\n- `ipOrHostname` (`string`): IP address (v4/v6) or a hostname.\n- `canBind` (`boolean`, default `false`): when `true`, additionally checks that the local machine can bind to the\n  address (i.e., it is configured on a local interface).\n\nThe function throws for invalid inputs (non-string values or syntactically invalid hostnames).\n\n## Caveats\n\nInternationalized domain names (IDNs) are not supported. If you need IDNs, use\n[Punycode.js](https://github.com/bestiejs/punycode.js) (or another punycode implementation) to convert the input\nto ASCII before calling this function:\n\n```js\nconst isLocalhost = require(\"is-localhost-ip\");\nconst punycode = require(\"punycode\");\n\n(async () =\u003e {\n  await isLocalhost(punycode.toASCII(\"свобода.рф\")); // false\n  await isLocalhost(punycode.toASCII(\"私の.家\")); // true\n})();\n```\n\n## License\n\n`is-localhost-ip` is available under the [MIT](https://mths.be/mit) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinovyatkin%2Fis-localhost-ip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinovyatkin%2Fis-localhost-ip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinovyatkin%2Fis-localhost-ip/lists"}