Skip to content

Instantly share code, notes, and snippets.

@schoblaska
Created May 7, 2022 20:23
Show Gist options
  • Save schoblaska/c7f614b5d31af8c990882f77d2b0363b to your computer and use it in GitHub Desktop.
Save schoblaska/c7f614b5d31af8c990882f77d2b0363b to your computer and use it in GitHub Desktop.
A Ruby script to wait for a device to return to the network, and then trigger some action
#!/usr/bin/env ruby
raise "run with rvmsudo" unless `whoami`.strip == "root"
class ThingDoer
def self.do_something
# TODO
end
end
macs = ENV["MACS"]
#
# Return of the MAC
#
loop do
nmap =
`nmap -sn 192.168.1.0/24 | grep -Eio "([0-9A-F]{2}:){5}[0-9A-F]{2}"`.split(
"\n"
)
detected = nmap.any? { |n| macs.include?(n.downcase) }
if detected
ThingDoer.do_something
exit
else
sleep 2
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment