Class: NetCrawl::Output
- Inherits:
-
Object
- Object
- NetCrawl::Output
- Defined in:
- lib/netcrawl/output.rb,
lib/netcrawl/output/dot.rb
Defined Under Namespace
Classes: Dot
Instance Attribute Summary collapse
-
#peers ⇒ Object
readonly
Returns the value of attribute peers.
-
#resolve ⇒ Object
readonly
Returns the value of attribute resolve.
Instance Method Summary collapse
-
#clean! ⇒ void
remove peers not matching to configured CIDR.
-
#resolve! ⇒ void
resolves ip addresses of peers and @peers keys.
-
#to_hash ⇒ String
Pretty print of hash.
-
#to_json ⇒ String
Json of hosts and peers found.
-
#to_list ⇒ Array
Of nodes found.
-
#to_yaml ⇒ String
Yaml of hosts and peers found.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object (private)
66 67 68 69 70 71 72 |
# 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 |
Instance Attribute Details
#peers ⇒ Object (readonly)
Returns the value of attribute peers.
3 4 5 |
# File 'lib/netcrawl/output.rb', line 3 def peers @peers end |
#resolve ⇒ Object (readonly)
Returns the value of attribute resolve.
3 4 5 |
# File 'lib/netcrawl/output.rb', line 3 def resolve @resolve end |
Instance Method Details
#clean! ⇒ void
This method returns an undefined value.
remove peers not matching to configured CIDR
52 53 54 55 56 |
# 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! ⇒ void
This method returns an undefined value.
resolves ip addresses of peers and @peers keys
39 40 41 42 43 44 45 46 47 48 |
# 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 ⇒ String
Returns pretty print of hash.
6 7 8 9 10 11 |
# File 'lib/netcrawl/output.rb', line 6 def to_hash require 'pp' out = '' PP.pp to_h, out out end |
#to_json ⇒ String
Returns json of hosts and peers found.
20 21 22 23 |
# File 'lib/netcrawl/output.rb', line 20 def to_json require 'json' JSON.pretty_generate to_h end |
#to_list ⇒ Array
Returns of nodes found.
26 27 28 29 30 31 32 33 34 35 |
# 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 ⇒ String
Returns yaml of hosts and peers found.
14 15 16 17 |
# File 'lib/netcrawl/output.rb', line 14 def to_yaml require 'yaml' YAML.dump to_h end |