Module: BetterCap::Shell
- Defined in:
- lib/bettercap/shell.rb
Overview
Class responsible of executing various shell commands.
Class Method Summary collapse
-
.arp ⇒ Object
Get the ARP table cached on this computer.
-
.available?(cmd) ⇒ Boolean
Cross-platform way of finding an executable in the $PATH.
-
.execute(command) ⇒ Object
Execute
commandand return its output. -
.ifconfig(iface = '') ⇒ Object
Get the
ifacenetwork interface configuration ( using ifconfig ). -
.ip(iface = '') ⇒ Object
Get the
ifacenetwork interface configuration ( using iproute2 ). -
.which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
Class Method Details
.arp ⇒ Object
Get the ARP table cached on this computer.
66 67 68 |
# File 'lib/bettercap/shell.rb', line 66 def arp self.execute( 'LANG=en && arp -a -n' ) end |
.available?(cmd) ⇒ Boolean
Cross-platform way of finding an executable in the $PATH.
51 52 53 |
# File 'lib/bettercap/shell.rb', line 51 def available?(cmd) !which(cmd).nil? end |
.execute(command) ⇒ Object
Execute command and return its output. Raise BetterCap::Error if the return code is not 0.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bettercap/shell.rb', line 21 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 ( using ifconfig ).
56 57 58 |
# File 'lib/bettercap/shell.rb', line 56 def ifconfig(iface = '') self.execute( "LANG=en && ifconfig #{iface}" ) end |
.ip(iface = '') ⇒ Object
Get the iface network interface configuration ( using iproute2 ).
61 62 63 |
# File 'lib/bettercap/shell.rb', line 61 def ip(iface = '') self.execute( "LANG=en && ip addr show #{iface}" ) end |
.which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bettercap/shell.rb', line 39 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) } end return nil end |