IP address handling library for Crystal language.
Add this to your application's shard.yml
:
dependencies:
ipaddr:
github: arcage/crystal-ipaddr
require "ipaddr"
ipv4 = IPAddr.new("169.254.10.1")
# => #<IPAddr:IPv4 "169.254.10.1">
ipv6 = IPAddr.new("2001:db8::deca:face")
# => #<IPAddr:IPv6 "2001:0db8:0000:0000:0000:0000:deca:face">
v4compat = ipv4.to_ipv4_compat
# => #<IPAddr:IPv6 "0000:0000:0000:0000:0000:0000:a9fe:0a01">
v4mapped = ipv4.to_ipv4_mapped
# => #<IPAddr:IPv6 "0000:0000:0000:0000:0000:ffff:a9fe:0a01">
v4compat.native_ipv4
# => #<IPAddr:IPv4 "169.254.10.1">
v4mapped.native_ipv4
# => #<IPAddr:IPv4 "169.254.10.1">
nw = IPAddr::NetworkAddr.new(ipv4, 16)
# => #<IPAddr::NetworkAddr:IPv4 "169.254.0.0/16">
nw2 = IPAddr::NetworkAddr.new("2001:db8::beaf:cafe", 120)
# => #<IPAddr::NetworkAddr:IPv6 "2001:0db8:0000:0000:0000:0000:beaf:ca00/120">
nw3 = IPAddr::NetworkAddr.new("192.168.20.2/255.255.255.0")
# => #<IPAddr::NetworkAddr:IPv4 "192.168.20.0/24">
nw4 = IPAddr::NetworkAddr.new("2001:db8::beaf:cafe/120")
# => #<IPAddr::NetworkAddr:IPv6 "2001:0db8:0000:0000:0000:0000:beaf:ca00/120">
nw.begin
# => #<IPAddr:IPv4 "169.254.0.0">
nw.end
# => #<IPAddr:IPv4 "169.254.255.255">
nw.includes?(ipv4)
# => true
- Fork it ( https://github.com/arcage/ipaddr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- arcage ʕ·ᴥ·ʔAKJ - creator, maintainer