Method: Rex::Socket.net2bitmask

Defined in:
lib/rex/socket.rb

.net2bitmask(netmask) ⇒ Object

Converts a netmask (255.255.255.240) into a bitmask (28). This is the lame kid way of doing it.



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/rex/socket.rb', line 471

def self.net2bitmask(netmask)

  nmask = resolv_nbo(netmask)
  imask = addr_ntoi(nmask)
  bits  = 32

  if (imask > 0xffffffff)
    bits = 128
  end

  0.upto(bits-1) do |bit|
    p = 2 ** bit
    return (bits - bit) if ((imask & p) == p)
  end

  0
end