Class: BetterCap::CoreOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/bettercap/options/core_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(iface) ⇒ CoreOptions

Returns a new instance of CoreOptions.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bettercap/options/core_options.rb', line 43

def initialize( iface )
  @iface           = iface
  @gateway         = nil
  @targets         = nil
  @logfile         = nil
  @log_timestamp   = false
  @silent          = false
  @debug           = false
  @ignore          = nil
  @discovery       = true
  @no_target_nbns  = false
  @packet_throttle = 0.0
  @check_updates   = false
end

Instance Attribute Details

#check_updatesObject

If true, bettercap will check for updates then exit.



41
42
43
# File 'lib/bettercap/options/core_options.rb', line 41

def check_updates
  @check_updates
end

#debugObject

If true will enable debug messages.



37
38
39
# File 'lib/bettercap/options/core_options.rb', line 37

def debug
  @debug
end

#discoveryObject

If false will disable active network discovery, the program will just use the current ARP cache.



27
28
29
# File 'lib/bettercap/options/core_options.rb', line 27

def discovery
  @discovery
end

#gatewayObject

Gateway IP address.



20
21
22
# File 'lib/bettercap/options/core_options.rb', line 20

def gateway
  @gateway
end

#ifaceObject

Network interface.



18
19
20
# File 'lib/bettercap/options/core_options.rb', line 18

def iface
  @iface
end

#ignoreObject

Comma separated list of ip addresses to ignore.



24
25
26
# File 'lib/bettercap/options/core_options.rb', line 24

def ignore
  @ignore
end

#log_timestampObject

If true the Logger will prepend timestamps to each line.



33
34
35
# File 'lib/bettercap/options/core_options.rb', line 33

def log_timestamp
  @log_timestamp
end

#logfileObject

Log file name.



31
32
33
# File 'lib/bettercap/options/core_options.rb', line 31

def logfile
  @logfile
end

#no_target_nbnsObject

If true, targets NBNS hostname resolution won’t be performed.



29
30
31
# File 'lib/bettercap/options/core_options.rb', line 29

def no_target_nbns
  @no_target_nbns
end

#packet_throttleObject

If different than 0, this time will be used as a delay while sending packets.



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

def packet_throttle
  @packet_throttle
end

#silentObject

If true will suppress every log message which is not an error or a warning.



35
36
37
# File 'lib/bettercap/options/core_options.rb', line 35

def silent
  @silent
end

#targetsObject

Comma separated list of targets.



22
23
24
# File 'lib/bettercap/options/core_options.rb', line 22

def targets
  @targets
end

Instance Method Details

#discovery?Boolean

Return true if active host discovery is enabled, otherwise false.

Returns:

  • (Boolean)


131
132
133
# File 'lib/bettercap/options/core_options.rb', line 131

def discovery?
  ( @discovery and @targets.nil? )
end

#ignore_ip?(ip) ⇒ Boolean

Return true if the ip address needs to be ignored, otherwise false.

Returns:

  • (Boolean)


180
181
182
# File 'lib/bettercap/options/core_options.rb', line 180

def ignore_ip?(ip)
  !@ignore.nil? and @ignore.include?(ip)
end

#parse!(ctx, opts) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/bettercap/options/core_options.rb', line 58

def parse!( ctx, opts )
  opts.separator ""
  opts.separator "MAIN:".bold
  opts.separator ""

  opts.on( '-I', '--interface IFACE', 'Network interface name - default: ' + @iface.to_s.yellow ) do |v|
    @iface = v
  end

  opts.on( '-G', '--gateway ADDRESS', 'Manually specify the gateway address, if not specified the current gateway will be retrieved and used. ' ) do |v|
    @gateway = v
    raise BetterCap::Error, "The specified gateway '#{v}' is not a valid IPv4 address." unless Network::Validator.is_ip?(v)
  end

  opts.on( '-T', '--target ADDRESS1,ADDRESS2', 'Target IP addresses, if not specified the whole subnet will be targeted.' ) do |v|
    self.targets = v
  end

  opts.on( '--ignore ADDRESS1,ADDRESS2', 'Ignore these addresses if found while searching for targets.' ) do |v|
    self.ignore = v
  end

  opts.on( '--no-discovery', "Do not actively search for hosts, just use the current ARP cache, default to #{'false'.yellow}." ) do
    @discovery = false
  end

  opts.on( '--no-target-nbns', 'Disable target NBNS hostname resolution.' ) do
    @no_target_nbns = true
  end

  opts.on( '--packet-throttle NUMBER', 'Number of seconds ( can be a decimal number ) to wait between each packet to be sent.' ) do |v|
    @packet_throttle = v.to_f
    raise BetterCap::Error, "Invalid packet throttle value specified." if @packet_throttle <= 0.0
  end

  opts.on( '--check-updates', 'Will check if any update is available and then exit.' ) do
    @check_updates = true
  end

  opts.on( '-h', '--help', 'Display the available options.') do
    puts opts
    puts "\nFor examples & docs please visit " + "http://bettercap.org/docs/".bold
    exit
  end

  opts.separator ""
  opts.separator "LOGGING:".bold
  opts.separator ""

  opts.on( '-O', '--log LOG_FILE', 'Log all messages into a file, if not specified the log messages will be only print into the shell.' ) do |v|
    @logfile = v
  end

  opts.on( '--log-timestamp', 'Enable logging with timestamps for each line, disabled by default.' ) do
    @log_timestamp = true
  end

  opts.on( '-D', '--debug', 'Enable debug logging.' ) do
    @debug = true
  end

  opts.on( '--silent', "Suppress every message which is not an error or a warning, default to #{'false'.yellow}." ) do
    @silent = true
  end

end

#validate!Object

Raises:



125
126
127
128
# File 'lib/bettercap/options/core_options.rb', line 125

def validate!
  raise BetterCap::Error, 'This software must run as root.' unless Process.uid == 0
  raise BetterCap::Error, 'No default interface found, please specify one with the -I argument.' if @iface.nil?
end