Created
May 8, 2016 11:33
-
-
Save tetherit/51645b2ba77062309b7d59ea7a9ff5a9 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
# gem install celluloid net-ping | |
require 'celluloid/current' | |
require 'net/ping' | |
require 'ipaddr' | |
class ScanWorker | |
include Celluloid | |
def ping(ip) | |
if system("ping -c1 -W1 #{ip} >/dev/null 2>&1") | |
arp = `arp #{ip} | awk '{ print $4 }'`.strip | |
[ip, arp] | |
end | |
end | |
end | |
def network_to_ips(network) | |
IPAddr.new(network).to_range.map(&:to_s)[1..-2] | |
end | |
pool = ScanWorker.pool(size: 50) | |
futures = network_to_ips('192.168.0.0/24').map do |ip| | |
pool.future.ping(ip) | |
end | |
futures.each do |future| | |
value = future.value | |
p value if value | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment