Class: Rex::Post::Meterpreter::Extensions::Stdapi::Net::Interface
- Inherits:
-
Object
- Object
- Rex::Post::Meterpreter::Extensions::Stdapi::Net::Interface
- Defined in:
- lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb
Overview
This class represents a logical physical interface on the remote machine.
Instance Attribute Summary collapse
-
#addrs ⇒ Object
An Array of IP addresses bound to the Interface.
-
#flags ⇒ Object
The flags associated with the interface.
-
#index ⇒ Object
The index of the interface.
-
#mac_addr ⇒ Object
The physical (MAC) address of the NIC.
-
#mac_name ⇒ Object
The name of the interface.
-
#mtu ⇒ Object
The MTU associated with the interface.
-
#netmasks ⇒ Object
An Array of netmasks.
-
#scopes ⇒ Object
An Array of IPv6 address scopes.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Interface
constructor
Returns a logical interface and initializes it to the supplied parameters.
-
#ip ⇒ Object
The first address associated with this Interface.
-
#pretty ⇒ Object
Returns a pretty string representation of the interface’s properties.
Constructor Details
#initialize(opts = {}) ⇒ Interface
Returns a logical interface and initializes it to the supplied parameters.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 31 def initialize(opts={}) self.index = opts[:index] || -1 self.mac_addr = opts[:mac_addr] self.mac_name = opts[:mac_name] self.mtu = opts[:mtu] self.flags = opts[:flags] self.addrs = opts[:addrs] self.netmasks = opts[:netmasks] self.scopes = opts[:scopes] end |
Instance Attribute Details
#addrs ⇒ Object
An Array of IP addresses bound to the Interface.
103 104 105 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 103 def addrs @addrs end |
#flags ⇒ Object
The flags associated with the interface.
119 120 121 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 119 def flags @flags end |
#index ⇒ Object
The index of the interface.
99 100 101 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 99 def index @index end |
#mac_addr ⇒ Object
The physical (MAC) address of the NIC.
107 108 109 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 107 def mac_addr @mac_addr end |
#mac_name ⇒ Object
The name of the interface.
111 112 113 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 111 def mac_name @mac_name end |
#mtu ⇒ Object
The MTU associated with the interface.
115 116 117 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 115 def mtu @mtu end |
#netmasks ⇒ Object
An Array of netmasks. This will have the same number of elements as #addrs
123 124 125 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 123 def netmasks @netmasks end |
#scopes ⇒ Object
An Array of IPv6 address scopes. This will have the same number of elements as #addrs
127 128 129 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 127 def scopes @scopes end |
Instance Method Details
#ip ⇒ Object
The first address associated with this Interface
92 93 94 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 92 def ip addrs.first end |
#pretty ⇒ Object
Returns a pretty string representation of the interface’s properties.
45 46 47 48 49 50 51 52 53 54 55 56 57 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 |
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb', line 45 def pretty macocts = [] mac_addr.each_byte { |o| macocts << o } macocts += [0] * (6 - macocts.size) if macocts.size < 6 info = [ ["Name" , mac_name ], ["Hardware MAC" , sprintf("%02x:%02x:%02x:%02x:%02x:%02x", macocts[0], macocts[1], macocts[2], macocts[3], macocts[4], macocts[5])], ["MTU" , mtu ], ["Flags" , flags ], ] # If all went as planned, addrs and netmasks will have the same number # of elements and be properly ordered such that they match up # correctly. addr_masks = addrs.zip(netmasks) addr_masks.select { |a| Rex::Socket.is_ipv4?(a[0]) }.each { |a| info << [ "IPv4 Address", a[0] ] info << [ "IPv4 Netmask", a[1] ] } addr_masks.select { |a| Rex::Socket.is_ipv6?(a[0]) }.each { |a| info << [ "IPv6 Address", a[0] ] info << [ "IPv6 Netmask", a[1] ] } pad = info.map{|i| i[0] }.max_by{|k|k.length}.length ret = sprintf( "Interface %2d\n" + "============\n", index ) info.map {|k,v| next if v.nil? ret << k.ljust(pad) + " : #{v}\n" } ret end |