Class: NetCrawl

Inherits:
Object
  • Object
show all
Defined in:
lib/netcrawl.rb,
lib/netcrawl/cli.rb,
lib/netcrawl/dns.rb,
lib/netcrawl/peer.rb,
lib/netcrawl/snmp.rb,
lib/netcrawl/config.rb,
lib/netcrawl/output.rb,
lib/netcrawl/namemap.rb,
lib/netcrawl/pollmap.rb,
lib/netcrawl/method/cdp.rb,
lib/netcrawl/method/xdp.rb,
lib/netcrawl/output/dot.rb,
lib/netcrawl/method/lldp.rb

Defined Under Namespace

Modules: NameMap Classes: CDP, CLI, LLDP, MethodNotFound, NetCrawlError, Output, Peer, PollMap, Resolve, SNMP, XDP

Constant Summary collapse

DNS =
Resolve.new
Config =
Asetus.new :name=>'netcrawl', :load=>false
CFG =
Config.cfg
Log =
Logger.new log

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostsObject (readonly)

Returns the value of attribute hosts.



5
6
7
# File 'lib/netcrawl.rb', line 5

def hosts
  @hosts
end

Instance Method Details

#crawl(host) ⇒ NetCrawl::Output

Parameters:

  • host (String)

    host to start crawl from

Returns:



9
10
11
12
# File 'lib/netcrawl.rb', line 9

def crawl host
  recurse host
  Output.new @hosts, @poll
end

#get(host) ⇒ Array

Returns list of peers seen connected to host.

Parameters:

  • host (String)

    host to get list of peers from

Returns:

  • (Array)

    list of peers seen connected to host



16
17
18
19
20
21
22
# File 'lib/netcrawl.rb', line 16

def get host
  peers = []
  @methods.each do |method|
    peers += method.send(:peers, host)
  end
  peers.uniq { |peer| peer.ip }
end

#recurse(host) ⇒ void

This method returns an undefined value.

Given string of IP address, recurses through peers seen and populates @hosts hash

Parameters:

  • host (String)

    host to start recurse from



27
28
29
30
31
32
33
34
35
# File 'lib/netcrawl.rb', line 27

def recurse host
  peers = get host
  @hosts[host] = peers
  peers.each do |peer|
    next if     @hosts.has_key? peer.ip
    next unless @poll.include?  peer.ip
    crawl peer.ip
  end
end