Created
May 7, 2022 20:23
-
-
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
This file contains hidden or 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 | |
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