Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arcage/crystal-ipaddr

IP address for Crystal language
https://github.com/arcage/crystal-ipaddr

Last synced: about 1 month ago
JSON representation

IP address for Crystal language

Awesome Lists containing this project

README

        

# IPAddr

IP address handling library for [Crystal language](https://crystal-lang.org).

## Installation

Add this to your application's `shard.yml`:

```yaml
dependencies:
ipaddr:
github: arcage/crystal-ipaddr
```

## Usage

```crystal
require "ipaddr"
```

### IP address object

```crystal
ipv4 = IPAddr.new("169.254.10.1")
# => #

ipv6 = IPAddr.new("2001:db8::deca:face")
# => #
```

### IPv4 compatible/mapped IPv6 address

```crystal
v4compat = ipv4.to_ipv4_compat
# => #

v4mapped = ipv4.to_ipv4_mapped
# => #

v4compat.native_ipv4
# => #

v4mapped.native_ipv4
# => #
```

### Network address

```crystal
nw = IPAddr::NetworkAddr.new(ipv4, 16)
# => #

nw2 = IPAddr::NetworkAddr.new("2001:db8::beaf:cafe", 120)
# => #

nw3 = IPAddr::NetworkAddr.new("192.168.20.2/255.255.255.0")
# => #

nw4 = IPAddr::NetworkAddr.new("2001:db8::beaf:cafe/120")
# => #

nw.begin
# => #

nw.end
# => #

nw.includes?(ipv4)
# => true

```
## Contributing

1. Fork it ( https://github.com/arcage/ipaddr/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request

## Contributors

- [arcage](https://github.com/arcage) ʕ·ᴥ·ʔAKJ - creator, maintainer