class NetCrawl::Output
Attributes
peers[R]
resolve[R]
Public Class Methods
new(peers, pollmap)
click to toggle source
# File lib/netcrawl/output.rb, line 60 def initialize peers, pollmap @peers = peers @pollmap = pollmap @resolve = false end
Public Instance Methods
clean!()
click to toggle source
remove peers not matching to configured CIDR @return [void]
# File lib/netcrawl/output.rb, line 52 def clean! @peers.each do |host, peers| peers.delete_if{|peer|not @pollmap.include? peer.ip} end end
resolve!()
click to toggle source
resolves ip addresses of peers and @peers keys @return [void]
# File lib/netcrawl/output.rb, line 39 def resolve! @resolve = true newpeers = {} @peers.each do |host, peers| peers.each { |peer| peer.name } name = DNS.getname host newpeers[name] = peers end @peers = newpeers end
to_hash()
click to toggle source
@return [String] pretty print of hash
# File lib/netcrawl/output.rb, line 6 def to_hash require 'pp' out = '' PP.pp to_h, out out end
to_json()
click to toggle source
@return [String] json of hosts and peers found
# File lib/netcrawl/output.rb, line 20 def to_json require 'json' JSON.pretty_generate to_h end
to_list()
click to toggle source
@return [Array] of nodes found
# File lib/netcrawl/output.rb, line 26 def to_list nodes = [] @peers.each do |host, peers| nodes << host peers.each do |peer| nodes.push @resolve ? peer.name : peer.ip end end nodes.flatten.uniq.sort end
to_yaml()
click to toggle source
@return [String] yaml of hosts and peers found
# File lib/netcrawl/output.rb, line 14 def to_yaml require 'yaml' YAML.dump to_h end
Private Instance Methods
method_missing(name, *args)
click to toggle source
# File lib/netcrawl/output.rb, line 66 def method_missing name, *args raise NoMethodError, "invalid method #{name} for #{inspect}:#{self.class}" unless name.match(/to_.*/) output = File.basename name[3..-1] require_relative 'output/' + output output = NetCrawl::Output.const_get output.capitalize output.send :output, self end
to_h()
click to toggle source
# File lib/netcrawl/output.rb, line 74 def to_h hash = {} @peers.each do |host, peers| ary = [] peers.each do |peer| ary << peer.to_hash end hash[host] = ary end hash end