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
139
140
141
142
143
144
145
146
|
# File 'lib/network_scanner.rb', line 112
def check_pings
raise Exception.new("Must specify ips to check(interface/range/cache)") unless @ips_to_check
@ips = []
pool = Thread.pool(@pool_size)
if self.output_name
out = File.open(self.output_name, 'w')
else
out = STDOUT
end
@ips_to_check.each do |ip|
pool.process do
if system("ping -c 1 #{ip} >> /dev/null 2> /dev/null")
@ips << ip
if text?
out.print "#{ip}\n"
end
end
end
end
pool.shutdown
if json?
out.puts(JSON.pretty_generate(@ips))
end
out.close unless out == STDOUT
return @ips
end
|