Module: BetterCap::Network
- Defined in:
- lib/bettercap/network/network.rb,
lib/bettercap/network/target.rb,
lib/bettercap/network/validator.rb,
lib/bettercap/network/arp_reader.rb,
lib/bettercap/network/protos/base.rb,
lib/bettercap/network/protos/dhcp.rb,
lib/bettercap/network/protos/ntlm.rb,
lib/bettercap/network/protos/snmp.rb,
lib/bettercap/network/packet_queue.rb,
lib/bettercap/network/protos/mysql.rb,
lib/bettercap/network/servers/dnsd.rb,
lib/bettercap/network/servers/httpd.rb
Overview
Handles various network related tasks.
Defined Under Namespace
Modules: Protos, Servers Classes: ArpReader, PacketQueue, Target, Validator
Class Method Summary collapse
-
.get_alive_targets(ctx) ⇒ Object
Return a list of BetterCap::Target objects found on the network, given a BetterCap::Context (
ctx
) and atimeout
in seconds for the operation. -
.get_gateway ⇒ Object
Return the current network gateway or nil.
-
.get_hw_address(ctx, ip) ⇒ Object
Return the hardware address associated with the specified
ip_address
using theiface
network interface. -
.get_ip_address(ctx, mac) ⇒ Object
Return the IP address associated with the
mac
hardware address using the given BetterCap::Context (ctx
). -
.get_local_ips ⇒ Object
Return a list of IP addresses associated to this device network interfaces.
Class Method Details
.get_alive_targets(ctx) ⇒ Object
Return a list of BetterCap::Target objects found on the network, given a BetterCap::Context ( ctx
) and a timeout
in seconds for the operation.
56 57 58 59 60 61 62 63 64 |
# File 'lib/bettercap/network/network.rb', line 56 def get_alive_targets( ctx ) if ctx..core.should_discover_hosts? start_agents( ctx ) else Logger.debug 'Using current ARP cache.' end ArpReader.parse ctx end |
.get_gateway ⇒ Object
Return the current network gateway or nil.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bettercap/network/network.rb', line 19 def get_gateway nstat = Shell.execute('netstat -nr') iface = Context.get..core.iface Logger.debug "NETSTAT:\n#{nstat}" nstat.split(/\n/).select {|n| n =~ /UG/ }.each do |line| Network::Validator.each_ip(line) do |address| return address end end nil end |
.get_hw_address(ctx, ip) ⇒ Object
Return the hardware address associated with the specified ip_address
using the iface
network interface.
79 80 81 82 83 84 85 86 |
# File 'lib/bettercap/network/network.rb', line 79 def get_hw_address( ctx, ip ) hw = ArpReader.find_address( ip ) if hw.nil? start_agents( ctx, ip ) hw = ArpReader.find_address( ip ) end hw end |
.get_ip_address(ctx, mac) ⇒ Object
Return the IP address associated with the mac
hardware address using the given BetterCap::Context ( ctx
).
68 69 70 71 72 73 74 75 |
# File 'lib/bettercap/network/network.rb', line 68 def get_ip_address( ctx, mac ) ip = ArpReader.find_mac( mac ) if ip.nil? start_agents( ctx ) ip = ArpReader.find_mac( mac ) end ip end |
.get_local_ips ⇒ Object
Return a list of IP addresses associated to this device network interfaces.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bettercap/network/network.rb', line 34 def get_local_ips ips = [] if Shell.available?('ip') Shell.ip.split("\n").each do |line| if line.strip =~ /^inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\/(\d+).+$/i ips << $1 end end else Shell.ifconfig.split("\n").each do |line| if line =~ /inet [adr:]*([\d\.]+)/ ips << $1 end end end ips end |