CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/meterpreter/extensions/stdapi/net/arp.rb
Views: 11797
1
# -*- coding: binary -*-
2
3
require 'ipaddr'
4
5
module Rex
6
module Post
7
module Meterpreter
8
module Extensions
9
module Stdapi
10
module Net
11
12
###
13
#
14
# This class represents an arp entry
15
# on the remote machine.
16
#
17
###
18
class Arp
19
20
##
21
#
22
# Constructor
23
#
24
##
25
26
#
27
# Returns an arp entry and initializes it to the supplied
28
# parameters.
29
#
30
def initialize(opts={})
31
self.ip_addr = IPAddr.new_ntoh(opts[:ip_addr]).to_s
32
self.mac_addr = mac_to_string(opts[:mac_addr])
33
self.interface = opts[:interface]
34
end
35
36
def mac_to_string(mac_addr)
37
macocts = []
38
mac_addr.each_byte { |o| macocts << o }
39
macocts += [0] * (6 - macocts.size) if macocts.size < 6
40
return sprintf("%02x:%02x:%02x:%02x:%02x:%02x",
41
macocts[0], macocts[1], macocts[2],
42
macocts[3], macocts[4], macocts[5])
43
end
44
45
#
46
# The ip address corresponding to the arp address.
47
#
48
attr_accessor :ip_addr
49
#
50
# The physical (MAC) address of the ARP entry
51
#
52
attr_accessor :mac_addr
53
#
54
# The name of the interface.
55
#
56
attr_accessor :interface
57
end
58
59
end; end; end; end; end; end
60
61