{"id":17114658,"url":"https://github.com/salieri/ipsubnetcalculator","last_synced_at":"2025-04-06T19:12:26.492Z","repository":{"id":6963547,"uuid":"8216014","full_name":"salieri/IPSubnetCalculator","owner":"salieri","description":"JavaScript module for calculating optimized subnet masks for standard and non-standard IP ranges, e.g. 5.4.3.21 - 6.7.8.9","archived":false,"fork":false,"pushed_at":"2024-02-28T01:15:08.000Z","size":150,"stargazers_count":77,"open_issues_count":1,"forks_count":24,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-06T19:12:21.297Z","etag":null,"topics":["cidr-prefixes","ip-masks","iprange","javascript","subnet-masks"],"latest_commit_sha":null,"homepage":"https://salieri.github.io/IPSubnetCalculator/","language":"TypeScript","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/salieri.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2013-02-15T09:55:18.000Z","updated_at":"2024-12-22T19:46:37.000Z","dependencies_parsed_at":"2024-06-18T15:23:22.854Z","dependency_job_id":null,"html_url":"https://github.com/salieri/IPSubnetCalculator","commit_stats":null,"previous_names":["franksrevenge/ipsubnetcalculator"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salieri%2FIPSubnetCalculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salieri%2FIPSubnetCalculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salieri%2FIPSubnetCalculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salieri%2FIPSubnetCalculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/salieri","download_url":"https://codeload.github.com/salieri/IPSubnetCalculator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247535519,"owners_count":20954576,"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":["cidr-prefixes","ip-masks","iprange","javascript","subnet-masks"],"created_at":"2024-10-14T17:19:42.145Z","updated_at":"2025-04-06T19:12:26.465Z","avatar_url":"https://github.com/salieri.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IP Subnet Calculator\nThis module calculates optimal subnet masks for non-standard IP ranges, e.g. `5.4.3.21 - 6.7.8.9`\n\n[View demo](http://salieri.github.io/IPSubnetCalculator/)\n\n\n## What does it do?\n* Calculates subnet masks for standard and non-standard IP ranges. For example, `10.0.0.5 - 10.0.0.23` will result in `10.0.0.5/32, 10.0.0.6/31, 10.0.0.8/29, 10.0.0.16/29`.\n* Calculates CIDR prefixes from subnet masks, e.g. `10.0.0.5/255.255.128.0` will result in `10.0.0.0/17`.\n* Calculates subnet masks from CIDR prefixes, e.g. `10.0.0.5/17` will result in `255.255.128.0`.\n\n\n## Support\n* Node.js\n* Direct browser use\n\n\n## Installation\n```sh\n\u003e npm install ip-subnet-calculator\n```\n\n\n## Node.js\n```javascript\nimport * as IPSubnetCalculator from 'ip-subnet-calculator';\n// or: const IPSubnetCalculator = require('ip-subnet-calculator');\n\nconsole.log(IPSubnetCalculator.isIp('127.0.0.1')); // true\nconsole.log(IPSubnetCalculator.toDecimal('127.0.0.1')); // 2130706433\n\nconsole.log(IPSubnetCalculator.calculate('5.4.3.21', '6.7.8.9'));\n```\n\n## Direct browser use\n```html\n\u003cscript src='lib/ip-subnet-calculator.browser.js'\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n    console.log(IPSubnetCalculator.isIp( 127.0.0.1')); // true\n    console.log(IPSubnetCalculator.toDecimal('127.0.0.1')); // 2130706433\n    \n    console.log(IPSubnetCalculator.calculate( '5.4.3.21', '6.7.8.9' ));\n\u003c/script\u003e\n```\n\n\n## API\n\n### IPSubnetCalculator.calculate(ipStart, ipEnd)\nCalculates an optimal set of IP masks for the given IP address range.\n\n\u003e *ipStart* (`string|number`) Lowest IP in the range to be calculated in string (`123.123.123.0`) or numeric (`2071689984`) format.\n\u003e \n\u003e *ipEnd* (`string|number`) Highest IP (inclusive) in the range to be calculated in string (`123.123.123.255`) or numeric (`2071690239`) format.\n\nThe function returns `null` in case of an error. Otherwise, an array containing one or more subnet\nmasks is returned:\n\n```javascript\nconst result = [\n  {\n    ipLow              : 2071689984,\n    ipLowStr           : \"123.123.123.0\",\n    ipHigh             : 2071690239,\n    ipHighStr          : \"123.123.123.255\",\n    prefixMask         : 4294967040,\n    prefixMaskStr      : \"255.255.255.0\",\n    prefixSize         : 24,\n    invertedMask       : 255,\n    invertedMaskStr    : \"0.0.0.255\",\n    invertedMaskSize   : 8\n  },\n  \n  ...\n];\n```\n\nEach object in question contain the following properties:\n\n| Property          | Use                                                            |\n:------------------|:---------------------------------------------------------------|\n| `ipLow`           | Decimal representation of the lowest IP address in the range   |\n| `ipLowStr`        | String representation of the lowest IP address in the range    |\n| `ipHigh`          | Decimal representation of the highest IP address in the range  |\n| `ipHighStr`       | String representation of the highest IP address in the range   |\n| `prefixMask`      | Decimal representation of the prefix (subnet) mask             |\n| `prefixMaskStr`   | String representation of the prefix (subnet) mask              |\n| `prefixSize`      | Size of the prefix (subnet) mask in bits                       |\n| `invertedMask`    | Decimal representation of the inverted prefix mask             |\n| `invertedMaskStr` | String representation of the inverted prefix mask              |\n| `invertedSize`    | Size of the inverted prefix max in bits                        |\n\n### IPSubnetCalculator.calculateSubnetMask(ip, prefixSize)\nCalculates a subnet mask from CIDR prefix.\n\n\u003e *ip* (`string|number`) IP address in string or numeric format\n\u003e \n\u003e *prefixSize* (`number`) Number of relevant bits in the subnet mask\n\nThe function returns an object containing full description of the IP range, as described in `IPSubnetCalculator.calculate()`.\n\n### IPSubnetCalculator.calculateCIDRPrefix(ip, subnetMask)\nCalculates a CIDR prefix from subnet mask.\n\n\u003e *ip* (`string|number`) IP address in string or numeric format\n\u003e\n\u003e *subnetMask* (`string|number`) IP subnet mask in string or numeric format\n\nThe function returns an object containing full description of the IP range, as described in `IPSubnetCalculator.calculate()`.\n\n\n## Test Functions\n\n### IPSubnetCalculator.isIp(ipStr)\nTests whether string is an IP address.\n\n\u003e *ipStr* (`string`) A string\n\nThe function returns a `true` if the string is an IP address, `false` otherwise.\n\n### IPSubnetCalculator.isDecimalIp(ipNum)\nTests whether `ipNum` is a decimal IP address.\n\n\u003e *ipNum* (`number`) A number\n\nThe function returns a `true` if the number is an IP address, `false` otherwise.\n\n\n## Conversion Functions\n\n### IPSubnetCalculator.toDecimal(ip)\nCalculates a decimal integer from an string IP address.\n\n\u003e *ip* (`string|number`) IP address in string format\n\nThe function returns a decimal representation of an IP address as an integer. If a valid numeric representation \nof an IP is passed to this function, it is returned unmodified.\n\nIf an invalid value is passed to the function, it will `throw` an `Error` object.\n\n\n### IPSubnetCalculator.toString(num)\n\u003e *num* (`number|string`) Decimal representation of an IP address.\n\nThe function returns an IP address as a string. If a valid string representation of an IP is passed to this function,\nit is returned unmodified.\n\nIf an invalid value is passed to the function, it will `throw` an `Error` object.\n\n\n## License\n[MIT](http://opensource.org/licenses/MIT)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalieri%2Fipsubnetcalculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalieri%2Fipsubnetcalculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalieri%2Fipsubnetcalculator/lists"}