Path: | README.rdoc |
Last Update: | Tue Jan 26 20:43:20 +0000 2010 |
This is a library for manipulating IP addresses. Feature overview:
require 'ip' ip = IP.new("192.0.2.53/24") ip.to_s # "192.0.2.53/24" ip.to_i # 3221226037 ip.to_hex # "c0000235" ip.to_addr # "192.0.2.53" ip.pfxlen # 24
ip = IP.new("192.0.2.53/24@cust1") ip.to_s # "192.0.2.53/24@cust1" ip.to_addrlen # "192.0.2.53/24" ip.ctx # "cust1"
ip1 = IP.new("192.0.2.53/24") #<IP::V4 192.0.2.53/24> ip2 = IP.new("2001:db8:be00::/48") #<IP::V6 2001:db8:be00::/48> ip1.is_a?(IP::V4) # true
ip = IP::V4.new(3221226037, 24, "cust1") ip = IP::V4.new("c0000235", 24, "cust1")
ip = IP.new("192.0.2.53/24") ip.network #<IP::V4 192.0.2.0/24> ip.network(1) #<IP::V4 192.0.2.1/24> ip.broadcast #<IP::V4 192.0.2.255/24> ip.broadcast(-1) #<IP::V4 192.0.2.254/24> ip.mask # 255 ip.size # 256 ip.netmask.to_s # "255.255.255.0" ip.wildmask.to_s # "0.0.0.255"
ip = IP.new("192.0.2.53/24") ip.offset? # true ip.offset # 53 ip.mask! ip.to_s # "192.0.2.0/24" ip.offset? # false
ip = IP.new("192.0.2.53/24") ip + 4 #<IP::V4 192.0.2.57/24> ip | 7 #<IP::V4 192.0.2.55/24> ip ^ 7 #<IP::V4 192.0.2.50/24> ~ip #<IP::V4 63.255.253.202/24>
ip1 = IP.new("192.0.2.53/24@cust1") ip1.to_a # ["v4", 3221226037, 24, "cust1"] ip2 = IP.new(["v4", 3221226037, 24, "cust1"]) ip1 == ip2 # true
ip1 = IP.new("2001:db8:be00::/48@cust1") ip1.to_ah # ["v6", "20010db8be0000000000000000000000", 48, "cust1"] ip2 = IP.new(["v6", "20010db8be0000000000000000000000", 48, "cust1"]) ip1 == ip2 # true
Ruby bundles an IPAddr class (ipaddr.rb). However there are a number of serious problems with this library.
You may use, distribute and modify this software under the same terms as ruby itself (see LICENSE.txt and COPYING.txt)