Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/arcage/crystal-ipaddr
- Owner: arcage
- License: mit
- Created: 2016-10-21T14:25:00.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-22T12:56:55.000Z (about 8 years ago)
- Last Synced: 2024-10-25T01:36:41.711Z (3 months ago)
- Language: Crystal
- Size: 6.84 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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```
## Contributing1. 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