Sha256: fd91ebd4d1b9be4e15439881f6632e7b84a1d7595d5424affc51ecef80f8ac23

Contents?: true

Size: 1.77 KB

Versions: 45

Compression:

Stored size: 1.77 KB

Contents

# $Revision: 1.1.1.1 $
# $Id: ifconfig.rb,v 1.1.1.1 2005/07/02 19:10:57 hobe Exp $

# = Ruby/Ifconfig - ruby interface to the information presented by ifconfig
#
# == Prerequisites
#
# You must have a working ifconfig binary in your path.
# The output format of you particular version of ifconfig must be supported.
# Currently this has only been tested with net-tool 1.6 on Linux
#
# == Example
# require 'ifconfig'
#
# cfg = IfconfigWrapper.new.parse        # parses the output of ifconfig
#
# cfg.interfaces()           # returns list of interfaces
#
# cfg[eth0].addresses('inet')   # returns ipv4 address of eth0
#
# cfg.addrresses('inet')        # returns list of all ipv4 addresses
#
# cfg[eth0].status   # returns true if interface is up
#
# cfg.each { block } # run a block on each interface object


#
# inspired by Net::Ifconfig::Wrapper perl module
# by Daniel Podolsky, <tpaba@cpan.org>
#
# Ruby version by Daniel Hobe <daniel@packetspike.net>
# Licence::  GPL[http://www.gnu.org/copyleft/gpl.html]
#

require 'ipaddr'

class IfconfigWrapper
  NAME = 'Ruby/Ifconfig'
  include Enumerable

  #
  # Can manually specify the platform (should be output of the 'uname' command)
  # and the ifconfig input
  #
  def initialize(platform=nil,input=nil,netstat=nil)
    platform = self.get_os unless !platform.nil?
    require "ifconfig/"+platform.downcase+"/ifconfig"
    @cfg = Ifconfig.new(input,netstat)
  end
  def parse
    return @cfg
  end
  # Find out what os we are on
  #
  def get_os
    plat = IO.popen('uname'){ |f| f.gets.strip }
    case plat
      when 'Windows'
        return plat
      when 'Linux'
        return plat
      when 'SunOS'
        return plat
      when 'FreeBSD','OpenBSD','NetBSD','DragonFly','Darwin'
        return 'BSD'
      else
        return 'Linux'
    end
  end
end

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
aaalex-ruby-ifconfig-1.2.1 lib/ifconfig.rb
aaalex-ruby-ifconfig-1.2.2 lib/ifconfig.rb
trema-0.4.7 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.4.6 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.4.5 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.4.4 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.4.3 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.4.2 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.4.1 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.4.0 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.3.21 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.3.20 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.3.19 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.3.18 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.3.17 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.3.16 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.3.15 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.3.14 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.3.13 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb
trema-0.3.12 vendor/ruby-ifconfig-1.2/lib/ifconfig.rb