Module: BetterCap::Shell

Defined in:
lib/bettercap/shell.rb

Overview

Class responsible of executing various shell commands.

Class Method Summary collapse

Class Method Details

.arpObject

Get the ARP table cached on this computer.


39
40
41
# File 'lib/bettercap/shell.rb', line 39

def arp
  self.execute( 'LANG=en && arp -a -n' )
end

.execute(command) ⇒ Object

Execute command and return its output. Raise BetterCap::Error if the return code is not 0.


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bettercap/shell.rb', line 16

def execute(command)
  r = ''
  10.times do
    begin
      r=%x(#{command})
      if $? != 0
        raise BetterCap::Error, "Error, executing #{command}"
      end
      break
    rescue Errno::EMFILE => e
      Logger.debug "Retrying command '#{command}' due to Errno::EMFILE error ..."
      sleep 1
    end
  end
  r
end

.ifconfig(iface = '') ⇒ Object

Get the iface network interface configuration.


34
35
36
# File 'lib/bettercap/shell.rb', line 34

def ifconfig(iface = '')
  self.execute( "LANG=en && ifconfig #{iface}" )
end