Created
December 3, 2010 13:59
-
-
Save hannesg/726980 to your computer and use it in GitHub Desktop.
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 | |
def online? | |
num = 0 | |
flag_regexp = /R[A-Z]*\n$/m | |
IO.popen("ifconfig -s").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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey buddy, you may want to ensure to close the process that you open. Regards