Module: Rex::Proto::NATPMP

Defined in:
lib/rex/proto/natpmp/packet.rb,
lib/rex/proto/natpmp/constants.rb

Constant Summary collapse

DefaultPort =
5351
Version =
0
TCP =
2
UDP =
1

Instance Method Summary collapse

Instance Method Details

#external_address_requestObject

Return a NAT-PMP request to get the external address.



15
16
17
# File 'lib/rex/proto/natpmp/packet.rb', line 15

def external_address_request
  [ 0, 0 ].pack('nn')
end

#map_port_request(lport, rport, protocol, lifetime) ⇒ Object

Return a NAT-PMP request to map remote port rport/protocol to local port lport for lifetime ms



27
28
29
30
31
32
33
34
35
# File 'lib/rex/proto/natpmp/packet.rb', line 27

def map_port_request(lport, rport, protocol, lifetime)
  [ Rex::Proto::NATPMP::Version, # version
    protocol, # opcode, which is now the protocol we are asking to forward
    0, # reserved
    lport,
    rport,
    lifetime
  ].pack("CCnnnN")
end

#parse_external_address_response(resp) ⇒ Object

Parse a NAT-PMP external address response resp. Returns the decoded parts of the response as an array.



21
22
23
24
# File 'lib/rex/proto/natpmp/packet.rb', line 21

def parse_external_address_response(resp)
  (ver, op, result, epoch, addr) = resp.unpack("CCnNN")
  [ ver, op, result, epoch, Rex::Socket::addr_itoa(addr) ]
end

#parse_map_port_response(resp) ⇒ Object

Parse a NAT-PMP mapping response resp. Returns the decoded parts as an array.



39
40
41
# File 'lib/rex/proto/natpmp/packet.rb', line 39

def parse_map_port_response(resp)
  resp.unpack("CCnNnnN")
end