Skip to content

Instantly share code, notes, and snippets.

@hannesg
Created December 3, 2010 13:59
Show Gist options
  • Save hannesg/726980 to your computer and use it in GitHub Desktop.
Save hannesg/726980 to your computer and use it in GitHub Desktop.
#!/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
@agpelliza
Copy link

Hey buddy, you may want to ensure to close the process that you open. Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment