class Bandshell::Interface
Some useful interface operations.
Attributes
name[R]
Get the name of the interface as a string.
Public Class Methods
new(name)
click to toggle source
Wrap an interface name (eth0, wlan0 etc) with some useful operations.
# File lib/bandshell/netconfig.rb, line 37 def initialize(name) @name = name end
Public Instance Methods
down()
click to toggle source
# File lib/bandshell/netconfig.rb, line 65 def down system("/sbin/ifconfig #{@name} down") end
ifdown()
click to toggle source
# File lib/bandshell/netconfig.rb, line 73 def ifdown system("/sbin/ifdown #{@name}") end
ifup()
click to toggle source
# File lib/bandshell/netconfig.rb, line 69 def ifup system("/sbin/ifup #{@name}") end
ip()
click to toggle source
Get the (first) IPv4 address assigned to the interface. Return “0.0.0.0” if we don’t have any v4 addresses.
# File lib/bandshell/netconfig.rb, line 46 def ip if ifconfig =~ /inet addr:([0-9.]+)/ $1 else "0.0.0.0" end end
mac()
click to toggle source
Get the physical (mac, ethernet) address of the interface.
# File lib/bandshell/netconfig.rb, line 55 def mac File.open("/sys/class/net/#{@name}/address") do |f| f.read.chomp end end
medium_present?()
click to toggle source
# File lib/bandshell/netconfig.rb, line 85 def medium_present? brought_up = false result = false if not up? brought_up = true up sleep 10 end if ifconfig =~ /RUNNING/ result = true end if brought_up down end result end
up()
click to toggle source
# File lib/bandshell/netconfig.rb, line 61 def up system("/sbin/ifconfig #{@name} up") end
up?()
click to toggle source
# File lib/bandshell/netconfig.rb, line 77 def up? if ifconfig =~ /UP/ true else false end end
Private Instance Methods
ifconfig()
click to toggle source
# File lib/bandshell/netconfig.rb, line 107 def ifconfig `/sbin/ifconfig #{@name}` end