Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tetherit/51645b2ba77062309b7d59ea7a9ff5a9 to your computer and use it in GitHub Desktop.
Save tetherit/51645b2ba77062309b7d59ea7a9ff5a9 to your computer and use it in GitHub Desktop.
#!/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