Last active
August 29, 2015 14:07
-
-
Save ross-nordstrom/9578a0de00f0a623726e to your computer and use it in GitHub Desktop.
Get a count of devices. Requires nmap (apt-get install nmap)
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 | |
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