Created
January 4, 2017 01:43
-
-
Save picatz/c9846675516defdab37ed2e1bfa52916 to your computer and use it in GitHub Desktop.
Writing another article. Following this mongo DB hype 'yo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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