Class: NetCrawl::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/netcrawl/output.rb,
lib/netcrawl/output/dot.rb

Defined Under Namespace

Classes: Dot

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)

Raises:

  • (NoMethodError)


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

#peersObject (readonly)

Returns the value of attribute peers.



3
4
5
# File 'lib/netcrawl/output.rb', line 3

def peers
  @peers
end

#resolveObject (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_hashString

Returns pretty print of hash.

Returns:

  • (String)

    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_jsonString

Returns json of hosts and peers found.

Returns:

  • (String)

    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_listArray

Returns of nodes found.

Returns:

  • (Array)

    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_yamlString

Returns yaml of hosts and peers found.

Returns:

  • (String)

    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