#!/usr/bin/env ruby # Copyright (2008) Sandia Corporation. # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, # the U.S. Government retains certain rights in this software. # # Original Author: Michael Berg, Sandia National Laboratories # Modified By: Bryan T. Richardson, Sandia National Laboratories # # This library is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or (at # your option) any later version. # # This library is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with this library; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA def print_help puts "Usage: antfarm [options] viz [options] display-networks" puts puts "This script utilizes the provided Prefuse-based Java application" puts "to display the networks contained in the current database." puts end def display output = File.open("#{Antfarm.tmp_dir_to_use}/network.gml", "w") output.puts "" output.puts "" output.puts " " output.puts " " output.puts " " output.puts " " networks = Array.new Node.find(:all).each do |node| created_node = false node.layer3_interfaces.each do |l3_if| network = Antfarm::IPAddrExt.new(l3_if.layer3_network.ip_network.address.to_s) unless created_node output.puts " " output.puts " #{node.name.nil? ? node.device_type : node.name}" output.puts " #{node.device_type}" output.puts " " created_node = true end unless networks.include?(l3_if.layer3_network.id) output.puts " " output.puts " #{l3_if.layer3_network.ip_network.address.to_s}" output.puts " #{l3_if.layer3_network.ip_network.private ? "PRIVATE" : "PUBLIC"}" output.puts " " networks << l3_if.layer3_network.id end output.puts " " end end node_list = Array.new Traffic.find(:all).each do |traffic| source_node = traffic.source_layer3_interface.layer2_interface.node target_node = traffic.target_layer3_interface.layer2_interface.node unless node_list.include?(source_node) output.puts " " output.puts " #{source_node.name.nil? ? source_node.device_type : source_node.name}" output.puts " #{source_node.device_type}" output.puts " " end unless node_list.include?(target_node) output.puts " " output.puts " #{target_node.name.nil? ? target_node.device_type : target_node.name}" output.puts " #{target_node.device_type}" output.puts " " end output.puts " " output.puts " PCAP" output.puts " " end output.puts " " output.puts "" output.close if (defined? USER_DIR) && File.exists?("#{USER_DIR}/config/colors.xml") `java -jar #{ANTFARM_ROOT}/lib/antfarm.jar -active -colors #{USER_DIR}/config/colors.xml #{Antfarm.tmp_dir_to_use}/network.gml` else `java -jar #{ANTFARM_ROOT}/lib/antfarm.jar -active #{Antfarm.tmp_dir_to_use}/network.gml` end end if ARGV.length > 0 print_help else display end