Class: PacketFu::Config
- Inherits:
-
Object
- Object
- PacketFu::Config
- Defined in:
- lib/packetfu/config.rb
Overview
The Config class holds various bits of useful default information for packet creation. If initialized without arguments, @iface will be set to ENV or Pcap.lookupdev (or lo), and the @pcapfile will be set to “/tmp/out.pcap” # (yes, it’s Linux-biased, sorry, fixing this is a TODO.)
Any number of instance variables can be passed in to the intialize function (as a hash), though only the expected network-related variables will be readable and writeable directly.
Examples
PacketFu::Config.new(:ip_saddr => "1.2.3.4").ip_saddr #=> "1.2.3.4"
PacketFu::Config.new(:foo=>"bar").foo #=> NomethodError: undefined method `foo'...
The config() function, however, does provide access to custom variables:
PacketFu::Config.new(:foo=>"bar").config[:foo] #=> "bar"
obj = PacketFu::Config.new(:foo=>"bar")
obj.config(:baz => "bat")
obj.config #=> {:iface=>"eth0", :baz=>"bat", :pcapfile=>"/tmp/out.pcap", :foo=>"bar"}
Instance Attribute Summary collapse
-
#eth_daddr ⇒ Object
The discovered eth_saddr.
-
#eth_dst ⇒ Object
The discovered eth_saddr.
-
#eth_saddr ⇒ Object
The discovered eth_saddr.
-
#eth_src ⇒ Object
The discovered eth_saddr.
-
#iface ⇒ Object
The discovered eth_saddr.
-
#ip_saddr ⇒ Object
The discovered eth_saddr.
-
#ip_src ⇒ Object
The discovered eth_saddr.
-
#pcapfile ⇒ Object
The discovered eth_saddr.
Instance Method Summary collapse
-
#config(arg = nil) ⇒ Object
Returns all instance variables as a hash (including custom variables set at initialization).
-
#initialize(args = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(args = {}) ⇒ Config
Returns a new instance of Config.
35 36 37 38 39 40 41 |
# File 'lib/packetfu/config.rb', line 35 def initialize(args={}) if Process.euid.zero? @iface = args[:iface] || ENV['IFACE'] || Pcap.lookupdev || "lo" end @pcapfile = "/tmp/out.pcap" args.each_pair { |k,v| self.instance_variable_set(("@#{k}"),v) } end |
Instance Attribute Details
#eth_daddr ⇒ Object
The discovered eth_saddr
26 27 28 |
# File 'lib/packetfu/config.rb', line 26 def eth_daddr @eth_daddr end |
#eth_dst ⇒ Object
The discovered eth_saddr
26 27 28 |
# File 'lib/packetfu/config.rb', line 26 def eth_dst @eth_dst end |
#eth_saddr ⇒ Object
The discovered eth_saddr
26 27 28 |
# File 'lib/packetfu/config.rb', line 26 def eth_saddr @eth_saddr end |
#eth_src ⇒ Object
The discovered eth_saddr
26 27 28 |
# File 'lib/packetfu/config.rb', line 26 def eth_src @eth_src end |
#iface ⇒ Object
The discovered eth_saddr
26 27 28 |
# File 'lib/packetfu/config.rb', line 26 def iface @iface end |
#ip_saddr ⇒ Object
The discovered eth_saddr
26 27 28 |
# File 'lib/packetfu/config.rb', line 26 def ip_saddr @ip_saddr end |
#ip_src ⇒ Object
The discovered eth_saddr
26 27 28 |
# File 'lib/packetfu/config.rb', line 26 def ip_src @ip_src end |
#pcapfile ⇒ Object
The discovered eth_saddr
26 27 28 |
# File 'lib/packetfu/config.rb', line 26 def pcapfile @pcapfile end |
Instance Method Details
#config(arg = nil) ⇒ Object
Returns all instance variables as a hash (including custom variables set at initialization).
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/packetfu/config.rb', line 44 def config(arg=nil) if arg arg.each_pair {|k,v| self.instance_variable_set(("@" + k.to_s).to_sym, v)} else config_hash = {} self.instance_variables.each do |v| key = v.to_s.gsub(/^@/,"").to_sym config_hash[key] = self.instance_variable_get(v) end config_hash end end |