Class: BetterCap::Network::Target
- Inherits:
-
Object
- Object
- BetterCap::Network::Target
- Defined in:
- lib/bettercap/network/target.rb
Overview
network.
Constant Summary collapse
- NBNS_TIMEOUT =
Timeout in seconds for the NBNS hostname resolution request.
30
- NBNS_PORT =
UDP port for the NBNS hostname resolution request.
137
- NBNS_BUFSIZE =
Buffer size for the NBNS hostname resolution request.
65536
- NBNS_REQUEST =
NBNS hostname resolution request buffer.
"\x82\x28\x0\x0\x0\x1\x0\x0\x0\x0\x0\x0\x20\x43\x4B\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x0\x0\x21\x0\x1"
- @@prefixes =
nil
- @@lock =
Mutex.new
Instance Attribute Summary collapse
-
#ip ⇒ Object
The IP address of this device.
-
#ip_refresh ⇒ Object
True if the IP attribute of this target needs to be updated.
-
#mac ⇒ Object
The MAC address of the device network interface.
-
#name ⇒ Object
NetBIOS hostname of the device if available OR interface name in case of local address.
-
#network ⇒ Object
Network object.
-
#vendor ⇒ Object
Vendor of the device network interface if available.
Class Method Summary collapse
Instance Method Summary collapse
-
#equals?(ip, mac) ⇒ Boolean
Return true if this
Target
is equal to the specifiedip
andmac
, otherwise return false. -
#initialize(ip, mac = nil, network = nil, name = nil) ⇒ Target
constructor
Create a
Target
object given itsip
and (optional)mac
address. -
#sortable_ip ⇒ Object
Return the integer representation of the
ip
attribute which can be used for sorting a list ofTarget
objects+. -
#spoofable? ⇒ Boolean
Return true if both the ip and mac are not nil.
-
#to_s(padding = true) ⇒ Object
Return a verbose string representation of this object.
-
#to_s_compact ⇒ Object
Return a compact string representation of this object.
Constructor Details
#initialize(ip, mac = nil, network = nil, name = nil) ⇒ Target
Create a Target
object given its ip
and (optional) mac
address. The ip
argument could also be a MAC address itself, in this case the ip address will be parsed from the computer ARP cache and updated accordingly.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bettercap/network/target.rb', line 49 def initialize( ip, mac=nil, network=nil, name=nil ) if Network::Validator.is_ip?(ip) @ip = ip @ip_refresh = false elsif Network::Validator.is_mac?(ip) @ip = nil mac = ip @ip_refresh = true else raise BetterCap::Error, "'#{ip}' is not a valid IP or MAC address." end @mac = Target.normalized_mac(mac) unless mac.nil? @vendor = Target.lookup_vendor(@mac) unless mac.nil? @name = name @network = network @resolver = Thread.new { resolve! } unless Context.get..core.no_target_nbns or @ip.nil? or !@network.nil? end |
Instance Attribute Details
#ip ⇒ Object
The IP address of this device.
20 21 22 |
# File 'lib/bettercap/network/target.rb', line 20 def ip @ip end |
#ip_refresh ⇒ Object
True if the IP attribute of this target needs to be updated.
31 32 33 |
# File 'lib/bettercap/network/target.rb', line 31 def ip_refresh @ip_refresh end |
#mac ⇒ Object
The MAC address of the device network interface.
22 23 24 |
# File 'lib/bettercap/network/target.rb', line 22 def mac @mac end |
#name ⇒ Object
NetBIOS hostname of the device if available OR interface name in case of local address.
29 30 31 |
# File 'lib/bettercap/network/target.rb', line 29 def name @name end |
#network ⇒ Object
Network object.
24 25 26 |
# File 'lib/bettercap/network/target.rb', line 24 def network @network end |
#vendor ⇒ Object
Vendor of the device network interface if available.
26 27 28 |
# File 'lib/bettercap/network/target.rb', line 26 def vendor @vendor end |
Class Method Details
.normalized_mac(v) ⇒ Object
122 123 124 |
# File 'lib/bettercap/network/target.rb', line 122 def self.normalized_mac(v) v.split(':').map { |e| e.size == 2 ? e.upcase : "0#{e.upcase}" }.join(':') end |
Instance Method Details
#equals?(ip, mac) ⇒ Boolean
Return true if this Target
is equal to the specified ip
and mac
, otherwise return false.
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/bettercap/network/target.rb', line 109 def equals?(ip, mac) # compare by ip if mac.nil? return ( @ip == ip ) # compare by mac elsif !@mac.nil? and ( @mac == mac ) Logger.info "Found IP #{ip} for target #{@mac}!" if @ip.nil? @ip = ip return true end false end |
#sortable_ip ⇒ Object
Return the integer representation of the ip
attribute which can be used for sorting a list of Target
objects+
70 71 72 |
# File 'lib/bettercap/network/target.rb', line 70 def sortable_ip @ip.split('.').inject(0) {|total,value| (total << 8 ) + value.to_i} end |
#spoofable? ⇒ Boolean
Return true if both the ip and mac are not nil.
75 76 77 |
# File 'lib/bettercap/network/target.rb', line 75 def spoofable? ( !@ip.nil? and !@mac.nil? ) end |
#to_s(padding = true) ⇒ Object
Return a verbose string representation of this object.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/bettercap/network/target.rb', line 87 def to_s(padding=true) address = @ip.nil?? '???' : @ip fmt = padding ? '%-15s : %-17s' : '%s : %s' vendor = @vendor.nil?? " ( ??? )" : " ( #{@vendor} )" s = sprintf( fmt, address, @mac ) s += " / #{@name}" unless @name.nil? s += vendor s end |
#to_s_compact ⇒ Object
Return a compact string representation of this object.
99 100 101 102 103 104 105 |
# File 'lib/bettercap/network/target.rb', line 99 def to_s_compact if @name "#{@name}/#{@ip}" else @ip end end |