Skip to content

Instantly share code, notes, and snippets.

@picatz
Created January 4, 2017 01:43
Show Gist options
  • Save picatz/c9846675516defdab37ed2e1bfa52916 to your computer and use it in GitHub Desktop.
Save picatz/c9846675516defdab37ed2e1bfa52916 to your computer and use it in GitHub Desktop.
Writing another article. Following this mongo DB hype 'yo.
require 'mongo'
require 'trollop'
require 'colorize'
foo = ARGV[0] || ARGV[0] = '-h'
opts = Trollop::options do
banner "Mongo Mauler".red.blue + " | " + "NoSQL? No Problem!".white.bold
version "Mongo Mauler v 1.0"
opt :ip, "Specify a host ip address to work with", :type => :string, :default => '127.0.0.1'
opt :port, "Specify a host port to work with", :type => :string, :default => '27017'
opt :start, "Start the audit"
end
def connect_to_db(args={})
ip = args[:ip] || '127.0.0.1'
port = args[:port] || '27017'
begin
client = Mongo::Client.new(["#{ip}:#{port}"])
rescue Mongo::Auth::Unauthorized, Mongo::Error => e
puts "Error #{e.class}: #{e.message}"
end
end
if opts[:start]
connect_to_db(opts)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment