network_scanner 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/network_scanner +13 -0
- data/lib/network_scanner/version.rb +1 -1
- data/lib/network_scanner.rb +39 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 152aa75da4f7d795bc59135d594290359b495d6b
|
4
|
+
data.tar.gz: e2c307e1ec491085a0407b664d1667902ddd1c64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1950c384ab54fccb77704967ba97895a3663f3e33ca901f17573e61259f9b2265e7c2ceb6b91579d21dc5762d2fc8d55ca278da8163c1bc34bb7d668791ee5f
|
7
|
+
data.tar.gz: 26b0ca80e612f5f44975c266b5b8ce6b914dfc28339553ad77cba58664afc4d9e8a8a9e4277df3fa9d8873404769e86c2d35cb9d017ae41131d95ba465c52be2
|
data/bin/network_scanner
CHANGED
@@ -33,10 +33,19 @@ OptionParser.new do |opts|
|
|
33
33
|
options[:port] = port
|
34
34
|
end
|
35
35
|
|
36
|
+
opts.on('-n', '--nslookup', 'Lookup hostnames of machines') do
|
37
|
+
options[:nslookup] = true
|
38
|
+
end
|
39
|
+
|
36
40
|
opts.on('-o', '--output OUTPUTFILE', String, 'File to output to') do |file|
|
37
41
|
options[:output] = file
|
38
42
|
end
|
39
43
|
|
44
|
+
opts.on_tail('-v', '--version', 'Show version number') do
|
45
|
+
puts NetworkScanner::VERSION
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
|
40
49
|
opts.on_tail('-h', '--help', 'Show help message') do
|
41
50
|
puts opts
|
42
51
|
exit
|
@@ -81,3 +90,7 @@ end
|
|
81
90
|
if options[:port]
|
82
91
|
network_scanner.check_ports(options[:port])
|
83
92
|
end
|
93
|
+
|
94
|
+
if options[:nslookup]
|
95
|
+
network_scanner.check_hostnames
|
96
|
+
end
|
data/lib/network_scanner.rb
CHANGED
@@ -191,5 +191,44 @@ module NetworkScanner
|
|
191
191
|
|
192
192
|
return @ips
|
193
193
|
end
|
194
|
+
|
195
|
+
def check_hostnames
|
196
|
+
raise Exception.new("Must scan ips first (Specify an interface or cacheread)") unless @ips_to_check
|
197
|
+
|
198
|
+
puts "Scanning for hostnames out of a total of #{@ips_to_check.length} ips"
|
199
|
+
|
200
|
+
if self.output_name
|
201
|
+
out = File.open(self.output_name, 'w')
|
202
|
+
else
|
203
|
+
out = STDOUT
|
204
|
+
end
|
205
|
+
|
206
|
+
pool = Thread.pool(@pool_size)
|
207
|
+
|
208
|
+
@ip_hosts = []
|
209
|
+
|
210
|
+
@ips_to_check.each do |ip|
|
211
|
+
pool.process do
|
212
|
+
scan = `nslookup #{ip}`
|
213
|
+
hostname = scan[/name\ =\ (.*)\n/, 1]
|
214
|
+
if hostname
|
215
|
+
@ip_hosts << [ip, hostname]
|
216
|
+
if text?
|
217
|
+
out.print "#{hostname} => #{ip}\n"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
pool.shutdown
|
224
|
+
|
225
|
+
if json?
|
226
|
+
out.puts(JSON.pretty_generate(@ip_hosts))
|
227
|
+
end
|
228
|
+
|
229
|
+
out.close unless out == STDOUT
|
230
|
+
|
231
|
+
return @ip_hosts
|
232
|
+
end
|
194
233
|
end
|
195
234
|
end
|