Sha256: c87fed48ef4a212202221512c8477079fd13715ecc33cb9027578be23dcefad3

Contents?: true

Size: 875 Bytes

Versions: 5

Compression:

Stored size: 875 Bytes

Contents

require 'ipaddr'

class Sapluuna
  class IP < IPAddr

    def initialize(addr = '::', family = Socket::AF_UNSPEC)
      addr_org, _family_org = addr, family
      prefix, _prefixlen = addr_org.split('/')
      @addr_org = prefix
      super
      if @family == Socket::AF_UNSPEC or @family == Socket::AF_INET
        @addr_org = in_addr(@addr_org)
      else
        @addr_org = in6_addr(@addr_org)
      end
    end

    def ip
      addr_tmp = @addr
      @addr = @addr_org
      ip = self.to_s
      @addr = addr_tmp
      ip
    end

    def mask_cidr
      @mask_addr.to_s(2).delete('0').size
    end

    def mask_wild
      _to_string ~@mask_addr
    end

    def mask_net
      _to_string @mask_addr
    end

    def cidr
      ip + '/' + mask_cidr.to_s
    end

    def acl
      ip + ' '+ mask_wild
    end

    def net
      ip + ' ' + mask_net
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sapluuna-0.2.0 lib/sapluuna/ip.rb
sapluuna-0.1.7 lib/sapluuna/ip.rb
sapluuna-0.1.6 lib/sapluuna/ip.rb
sapluuna-0.1.5 lib/sapluuna/ip.rb
sapluuna-0.1.4 lib/sapluuna/ip.rb