Skip to content

Instantly share code, notes, and snippets.

@ross-nordstrom
Last active August 29, 2015 14:07
Show Gist options
  • Save ross-nordstrom/9578a0de00f0a623726e to your computer and use it in GitHub Desktop.
Save ross-nordstrom/9578a0de00f0a623726e to your computer and use it in GitHub Desktop.
Get a count of devices. Requires nmap (apt-get install nmap)
#!/usr/bin/env ruby
require 'json'
me = `nmap --iflist | grep eth0`
myIp = me.split("\n")[0].split(' ')[2]
devices = `nmap -sP #{myIp}`
deviceCount = devices.split("\n").select{|l| l.include?('Host is up') }.size
#devices = `sudo nmap -sP #{myIp}`
#deviceCountSudo = devices.split("\n").select{|l| l.include?('Host is up') }.size
deviceData = {
:basicCount => deviceCount
# :sudoCount => deviceCountSudo
}
puts deviceData.to_json.gsub(/"/, "'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment