-
-
Save jvillarejo/5421730 to your computer and use it in GitHub Desktop.
Updated so it doesn't leave defunct ifconfig processes
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 | |
def online? | |
num = 0 | |
flag_regexp = /R[A-Z]*\n$/m | |
process = IO.popen("ifconfig -s") | |
process.each do |line| | |
num = num + 1 | |
# ignore first line | |
next if num == 1 | |
# ignore lo | |
next if line[0,2] == 'lo' | |
# test if this interface has the 'R' flag | |
return true if flag_regexp =~ line | |
end | |
return false | |
ensure | |
process.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment