forked from michenriksen/aquatone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aquatone-discover
executable file
·138 lines (121 loc) · 3.98 KB
/
aquatone-discover
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env ruby
require "aquatone"
options = {
:fallback_nameservers => %w(8.8.8.8 8.8.4.4),
:threads => 5,
:ignore_private => true
}
OptionParser.new do |opts|
opts.banner = "Usage: aquatone-discover OPTIONS"
opts.on("-d", "--domain DOMAIN", "Domain name to assess") do |v|
if !Aquatone::Validation.valid_domain_name?(v)
puts "#{v} doesn't look like a valid domain name."
exit 1
end
options[:domain] = v
end
opts.on("--nameservers NAMESERVERS", "Nameservers to use") do |v|
ips = v.split(",").map(&:strip).uniq
if ips.empty?
puts "Nameservers can't be empty."
exit 1
end
ips.each do |ip|
if !Aquatone::Validation.valid_ip?(ip)
puts "#{ip} is not a valid IP address."
exit 1
end
end
options[:nameservers] = ips
end
opts.on("--fallback-nameservers NAMESERVERS", "Nameservers to fall back to") do |v|
ips = v.split(",").map(&:strip).uniq
if ips.empty?
puts "Fallback nameservers can't be empty."
exit 1
end
ips.each do |ip|
if !Aquatone::Validation.valid_ip?(ip)
puts "#{ip} is not a valid IP address."
exit 1
end
end
options[:fallback_nameservers] = ips
end
opts.on("--[no-]ignore-private", "Ignore hosts resolving to private IP addresses") do |v|
options[:ignore_private] = v
end
opts.on("--set-key KEY VALUE", "Save a key to key store") do |key|
if ARGV.empty?
puts "No key value given."
exit 1
end
key = key.to_s.downcase
value = ARGV.join(" ").strip
Aquatone::KeyStore.set(key, value)
puts "Saved key #{key} with value #{value}."
exit
end
opts.on("--list-collectors", "See information on collectors") do
Aquatone::Collector.descendants.each do |collector|
puts "Name............: #{collector.meta[:name]}"
puts "Description.....: #{collector.meta[:description]}" if collector.meta[:description]
puts "Author..........: #{collector.meta[:author]}"
puts "Key Requirements: #{collector.meta.key?(:require_keys) ? collector.meta[:require_keys].join(', ') : 'None'}"
puts "Key.............: #{collector.sluggified_name}\n\n"
puts "--------------------------------------------------\n\n"
end
exit
end
opts.on("--only-collectors COLLECTORS", "Only run specified collectors") do |v|
known_collectors = Aquatone::Collector.descendants.map(&:sluggified_name)
collectors = v.split(",").map(&:strip).uniq
collectors.each do |collector|
if !known_collectors.include?(collector)
puts "Unknown collector key: #{collector}"
exit 1
end
end
options[:only_collectors] = collectors
end
opts.on("--disable-collectors COLLECTORS", "Disable specified collectors") do |v|
known_collectors = Aquatone::Collector.descendants.map(&:sluggified_name)
collectors = v.split(",").map(&:strip).uniq
collectors.each do |collector|
if !known_collectors.include?(collector)
puts "Unknown collector key: #{collector}"
exit 1
end
end
options[:disable_collectors] = collectors
end
opts.on("-t", "--threads THREADS", "Number of concurrent threads to use") do |v|
options[:threads] = v.to_i
end
opts.on("-s", "--sleep SECONDS", "Seconds to sleep between lookups") do |v|
if v.to_i < 1
puts "Sleep can't be less than 1"
exit 1
end
options[:sleep] = v.to_i
end
opts.on("-j", "--jitter PERCENTAGE", "Jitter factor for sleep intervals") do |v|
if !v.to_i.between?(1, 100)
puts "Jitter factor must be between 1 and 100"
exit 1
end
options[:jitter] = v.to_f
end
Aquatone::Collector.descendants.each do |collector|
collector.cli_options.each_pair do |option, description|
opts.on("--#{option}", description) do |v|
options[option.split(" ").first.gsub("-", "_").to_sym] = v
end
end
end
opts.on("-h", "--help", "Show help") do
puts opts
exit 0
end
end.parse!
Aquatone::Commands::Discover.run(options)