network_scanner 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9bdf3586d28cb2c6ba41ce2337d054d1ebcb041
4
- data.tar.gz: 23164e74226b74b5f02f50dbe5c212778d3db68d
3
+ metadata.gz: 152aa75da4f7d795bc59135d594290359b495d6b
4
+ data.tar.gz: e2c307e1ec491085a0407b664d1667902ddd1c64
5
5
  SHA512:
6
- metadata.gz: f23d8cb010bd8f316a86aaa50d2f16b07725344a7c55e387c91e3b0678e29e89a977a194cf3d848a42262d3284c74c625587d879f9779f676f068ef906a0c8ee
7
- data.tar.gz: d54b2b76b0019752e3a9ef42d4a767d15cd8b6a3b423b3e81f49ce868ab35caf52ac7f0ed45084145c712e12ee177842c28ed65c9fcd28c8224bd36a50d064e8
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
@@ -1,3 +1,3 @@
1
1
  module NetworkScanner
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: network_scanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Neyer