{"id":13509284,"url":"https://github.com/c-rack/cidr-elixir","last_synced_at":"2025-04-07T10:21:48.505Z","repository":{"id":29906668,"uuid":"33452437","full_name":"c-rack/cidr-elixir","owner":"c-rack","description":"Classless Inter-Domain Routing (CIDR) for Elixir","archived":false,"fork":false,"pushed_at":"2024-06-24T18:24:49.000Z","size":89,"stargazers_count":45,"open_issues_count":0,"forks_count":18,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-31T09:05:48.077Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/c-rack.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2015-04-05T19:31:16.000Z","updated_at":"2024-08-06T07:48:57.000Z","dependencies_parsed_at":"2024-11-01T09:43:39.319Z","dependency_job_id":null,"html_url":"https://github.com/c-rack/cidr-elixir","commit_stats":{"total_commits":97,"total_committers":10,"mean_commits":9.7,"dds":0.4226804123711341,"last_synced_commit":"9072aaab069bca38ef55fd901a37448861596532"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-rack%2Fcidr-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-rack%2Fcidr-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-rack%2Fcidr-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-rack%2Fcidr-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/c-rack","download_url":"https://codeload.github.com/c-rack/cidr-elixir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247631833,"owners_count":20970069,"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-08-01T02:01:05.660Z","updated_at":"2025-04-07T10:21:48.466Z","avatar_url":"https://github.com/c-rack.png","language":"Elixir","funding_links":[],"categories":["Text and Numbers"],"sub_categories":[],"readme":"# CIDR\n\n[![Downloads](https://img.shields.io/hexpm/dt/cidr.svg)](https://hex.pm/packages/cidr)\n[![Hex.pm Version](http://img.shields.io/hexpm/v/cidr.svg)](https://hex.pm/packages/cidr)\n[![Build Status](https://travis-ci.org/c-rack/cidr-elixir.png?branch=master)](https://travis-ci.org/c-rack/cidr-elixir)\n[![Coverage Status](https://coveralls.io/repos/c-rack/cidr-elixir/badge.svg?branch=\u0026service=github)](https://coveralls.io/github/c-rack/cidr-elixir?branch=)\n[![Inline docs](http://inch-ci.org/github/c-rack/cidr-elixir.svg?branch=master)](http://inch-ci.org/github/c-rack/cidr-elixir)\n\n[Classless Inter-Domain Routing](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing)\n(CIDR) utilities for [Elixir](http://www.elixir-lang.org/)\n\n## Setup\n\nTo use this library, just add `:cidr` as a dependency to your `mix.exs` file:\n\n```elixir\ndefp deps do\n  [\n    {:cidr, \"\u003e= 1.1.0\"}\n  ]\nend\n```\n\n## Usage\n\nPassing an IP address string into `CIDR.parse` returns a `%CIDR{}` struct.\nIt contains the first and the last address of the range as Erlang IP tuples,\nthe amount of hosts the range covers and the network mask.\n\n```elixir\niex(1)\u003e cidr = \"1.2.3.4/24\" |\u003e CIDR.parse\n%CIDR{first: {1, 2, 3, 0}, last: {1, 2, 3, 255}, hosts: 256, mask: 24}\n```\n\nYou can query the struct for all of its fields:\n\n```elixir\niex(2)\u003e cidr.first\n{1, 2, 3, 0}\niex(3)\u003e cidr.hosts\n256\n```\n\nAnd use it to see if other IP addresses fall in the same range:\n\n```elixir\niex(4)\u003e cidr |\u003e CIDR.match!({1,2,3,100})\ntrue\niex(5)\u003e cidr |\u003e CIDR.match!({1,2,4,1})\nfalse\n```\n\nThe `match!/2` function also supports IP strings:\n\n```elixir\niex(6)\u003e cidr |\u003e CIDR.match!(\"1.2.3.100\")\ntrue\niex(7)\u003e cidr |\u003e CIDR.match!(\"1.2.4.1\")\nfalse\n```\n\nPlease note that `match!/2` throws an `ArgumentError` when you pass in a value\nthat does not represent a valid IP address or when you try to match an IPv4\naddress with an IPv6 range and vice-versa.\nWe also provide `match/2`, a non-throwing version that returns tagged tuples:\n\n```elixir\niex(8)\u003e cidr |\u003e CIDR.match(\"1.2.3.100\")\n{:ok, true}\niex(9)\u003e cidr |\u003e CIDR.match(\"1.2.4.1\")\n{:ok, false}\niex(10)\u003e cidr |\u003e CIDR.match(\"1.2.3.1000\")\n{:error, \"Tuple is not a valid IP address.\"}\n```\n\nIPv4 deaggregation works as well. It returns a list of the largest possible networks for an IPv4 range in the format of `$first_ip-$last_ip`:\n\n```elixir\niex(1)\u003e CIDR.parse_range(\"192.168.1.0-192.168.2.0\")\n[\n  %CIDR{first: {192, 168, 1, 0}, hosts: 256, last: {192, 168, 1, 255}, mask: 24},\n  %CIDR{first: {192, 168, 2, 0}, hosts: 1, last: {192, 168, 2, 0}, mask: 32}\n]\n```\n\n## Contribution\n\nSee [Collective Code Construction Contract (C4)](http://rfc.zeromq.org/spec:42/C4/)\n\n## License\n\n[Mozilla Public License 2.0](LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc-rack%2Fcidr-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc-rack%2Fcidr-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc-rack%2Fcidr-elixir/lists"}