Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/ui/console/command_dispatcher/db/common.rb
Views: 11789
# -*- coding: binary -*-12module Msf::Ui::Console::CommandDispatcher::Db::Common34#5# Returns true if the db is connected, prints an error and returns6# false if not.7#8# All commands that require an active database should call this before9# doing anything.10#11def active?12unless framework.db.active13print_error("Database not connected")14return false15end16true17end1819#20# Miscellaneous option helpers21#2223#24# Takes +host_ranges+, an Array of RangeWalkers, and chunks it up into25# blocks of 1024.26#27def each_host_range_chunk(host_ranges, &block)28# Chunk it up and do the query in batches. The naive implementation29# uses so much memory for a /8 that it's basically unusable (1.630# billion IP addresses take a rather long time to allocate).31# Chunking has roughly the same performance for small batches, so32# don't worry about it too much.33host_ranges.each do |range|34if range.nil? or range.length.nil?35chunk = nil36end_of_range = true37else38chunk = []39end_of_range = false40# Set up this chunk of hosts to search for41while chunk.length < 1024 and chunk.length < range.length42n = range.next_ip43if n.nil?44end_of_range = true45break46end47chunk << n48end49end5051# The block will do some52yield chunk5354# Restart the loop with the same RangeWalker if we didn't get55# to the end of it in this chunk.56redo unless end_of_range57end58end59end606162