lib/rfauxfactory.rb
# Generates a random IP address.
Generates a random IP address.
Generates a random IP address .
def gen_ipaddr(protocol: :ip4, prefix: [])
      raise ArgumentError, "#{protocol} is not valid protocol" unless IP_BLOCKS.key?(protocol)
      sections = IP_BLOCKS[protocol]
      prefix.map(&:to_s).compact
      sections -= prefix.length
      raise ArgumentError, "Prefix #{prefix} is too long for this configuration" if sections <= 0
      random_fields = if protocol == :ipv6
                        Array.new(sections) { rand(0..2**16 - 1).to_s(16) }
                      else
                        Array.new(sections) { rand(0..255) }
                      end
      ipaddr = (prefix + random_fields).join(IP_SEPARATOR[protocol])
      ipaddr += '.0' if protocol == :ip3
      ipaddr
    end
def gen_ipaddr ( protocol : :ip4 , prefix : [ ] ) raise ArgumentError , "#{protocol} is not valid protocol" unless IP_BLOCKS . key? ( protocol ) sections = IP_BLOCKS [ protocol ] prefix . map ( & :to_s ) . compact sections -= prefix . length raise ArgumentError , "Prefix #{prefix} is too long for this configuration" if sections <= 0 random_fields = if protocol == :ipv6 Array . new ( sections ) { rand ( 0 .. 2 ** 16 - 1 ) . to_s ( 16 ) } else Array . new ( sections ) { rand ( 0 .. 255 ) } end ipaddr = ( prefix + random_fields ) . join ( IP_SEPARATOR [ protocol ] ) ipaddr += '.0' if protocol == :ip3 ipaddr end
Generates a random IP address.
Generates a random IP address .
protocol
prefix