Skip to content

Commit

Permalink
add a util to populate an environment
Browse files Browse the repository at this point in the history
  • Loading branch information
jcran committed Feb 19, 2012
1 parent 7675cd2 commit 2557372
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
5 changes: 3 additions & 2 deletions features/step_definitions/network_audit_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
# Parse the nmap scan, and see if we have anything left
#
parser = Nmap::Parser.parsefile(@nmap_output_path)
parser.hosts("up") do |host|
@systems.should contain_host host
parser.hosts("up").each do |host|
puts "checking host #{host.addr}"
@systems.should contain_host host
end
end
8 changes: 6 additions & 2 deletions features/support/matchers/custom_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
RSpec::Matchers.define :contain_host do |host|
match do |expected_hosts|
@host = host
expected_hosts.include? @host.addr.to_s
if expected_hosts.include? @host.addr.to_s
true
else
false
end
end

failure_message_for_should do |expected_hosts|
Expand All @@ -12,5 +16,5 @@
failure_message_for_should_not do |expected_hosts|
"didn't expect to see #{@host.addr} in #{expected_hosts}"
end

end
29 changes: 29 additions & 0 deletions utils/configure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/ruby
#

require 'fileutils'
require 'nmap/parser'

env = ARGV[0]
range = ARGV[1].split(",")

puts "Configuring environment: #{env}"
puts "Using range: #{range}"

nmap_output_path = "/tmp/nmap_network_audit_#{rand(10000)}.xml"
nmap_command_line = "nmap -oX #{nmap_output_path} #{range.join(" ")}"

data_path = File.join(File.dirname(__FILE__), "..", "data")

`#{nmap_command_line}`

env_dir = File.join(data_path, env)

FileUtils.mkdir(env_dir) unless File.directory? env_dir

f = File.open(File.join(env_dir, "known_systems.txt"),"w")
parser = Nmap::Parser.parsefile(nmap_output_path)
parser.hosts("up").each do |host|
puts "found host #{host.addr}"
f.puts host.addr
end

0 comments on commit 2557372

Please sign in to comment.