### Home Classes Methods

### In Files

- lib/packetfu/inject.rb

### Parent

Object

### Methods

- ::new
- #a2w
- #array_to_wire
- #inject

### Files

- .document
- README.rdoc

### Class/Module Index

Quicksearch

- PacketFu
- PacketFu::ARPHeader
- PacketFu::ARPHeaderMixin
- PacketFu::ARPPacket
- PacketFu::AddrIpv6
- PacketFu::Capture
- PacketFu::Config
- PacketFu::EthHeader
- PacketFu::EthHeaderMixin
- PacketFu::EthMac
- PacketFu::EthNic
- PacketFu::EthOui
- PacketFu::EthPacket
- PacketFu::HSRPHeader
- PacketFu::HSRPHeaderMixin
- PacketFu::HSRPPacket
- PacketFu::ICMPHeader
- PacketFu::ICMPHeaderMixin
- PacketFu::ICMPPacket
- PacketFu::IPHeader
- PacketFu::IPHeaderMixin
- PacketFu::IPPacket
- PacketFu::IPv6Header
- PacketFu::IPv6HeaderMixin
- PacketFu::IPv6Packet
- PacketFu::Inject
- PacketFu::InvalidHeader
- PacketFu::InvalidPacket
- PacketFu::LLDPHeader
- PacketFu::LLDPHeaderMixin
- PacketFu::LLDPPacket
- PacketFu::Octets
- PacketFu::Packet
- PacketFu::PcapFile
- PacketFu::PcapHeader
- PacketFu::PcapPacket
- PacketFu::PcapPackets
- PacketFu::Read
- PacketFu::TCPHeader
- PacketFu::TCPHeaderMixin
- PacketFu::TCPPacket
- PacketFu::TcpEcn
- PacketFu::TcpFlags
- PacketFu::TcpHlen
- PacketFu::TcpOption
- PacketFu::TcpOption::ECHO
- PacketFu::TcpOption::ECHOREPLY
- PacketFu::TcpOption::EOL
- PacketFu::TcpOption::MSS
- PacketFu::TcpOption::NOP
- PacketFu::TcpOption::SACK
- PacketFu::TcpOption::SACKOK
- PacketFu::TcpOption::TS
- PacketFu::TcpOption::WS
- PacketFu::TcpOptions
- PacketFu::TcpReserved
- PacketFu::Timestamp
- PacketFu::UDPHeader
- PacketFu::UDPHeaderMixin
- PacketFu::UDPPacket
- PacketFu::Utils
- PacketFu::Write
- StructFu
- StructFu::Int
- StructFu::Int16
- StructFu::Int16be
- StructFu::Int16le
- StructFu::Int32
- StructFu::Int32be
- StructFu::Int32le
- StructFu::Int8
- StructFu::IntString
- StructFu::String
- Struct

No matching classes.

# PacketFu::Inject

The Inject class handles injecting arrays of binary data on the wire.

To inject single packets, use PacketFu::Packet.to_w() instead.

### Attributes

array[RW]
iface[R]
promisc[R]
show_live[RW]
snaplen[R]
stream[RW]
timeout[R]

### Public Class Methods

new(args={}) click to toggle source

    # File lib/packetfu/inject.rb, line 10
    def initialize(args={})
      @array = [] # Where the packet array goes.
      @stream = [] # Where the stream goes.
      @iface = args[:iface] || ENV['IFACE'] || Pcap.lookupdev || "lo"
      @snaplen = args[:snaplen] || 0xffff
      @promisc = args[:promisc] || false # Sensible for some Intel wifi cards
      @timeout = args[:timeout] || 1
      @show_live = nil
    end

### Public Instance Methods

a2w(args={}) click to toggle source

Equivalent to array_to_wire

    # File lib/packetfu/inject.rb, line 55
    def a2w(args={})
      array_to_wire(args)
    end

array_to_wire(args={}) click to toggle source

Takes an array, and injects them onto an interface. Note that complete packets (Ethernet headers on down) are expected.

### Parameters

    :array || arr
     An array of binary data (usually packet.to_s style).
    :int || sleep
     Number of seconds to sleep between injections (in float format)
    :show_live || :live
     If true, puts data about what was injected to stdout.

### Example

    inj = PacketFu::Inject.new
    inj.array_to_wire(:array => [pkt1, pkt2, pkt3], :sleep => 0.1)

    # File lib/packetfu/inject.rb, line 37
    def array_to_wire(args={})
      pkt_array = args[:array] || args[:arr] || @array
      interval = args[:int] || args[:sleep]
      show_live = args[:show_live] || args[:live] || @show_live

      @stream = Pcap.open_live(@iface,@snaplen,@promisc,@timeout)
      pkt_count = 0
      pkt_array.each do |pkt|
        @stream.inject(pkt)
        sleep interval if interval
        pkt_count +=1
        puts "Sent Packet \##{pkt_count} (#{pkt.size})" if show_live
      end
      # Return # of packets sent, array size, and array total size
      [pkt_count, pkt_array.size, pkt_array.join.size]
    end

inject(args={}) click to toggle source

Equivalent to array_to_wire

    # File lib/packetfu/inject.rb, line 60
    def inject(args={})
      array_to_wire(args)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.