class Stun::Client
Public Class Methods
new(options = {})
click to toggle source
# File lib/stun/client.rb, line 83 def initialize(options = {}) @host = options.fetch(:host, '108.177.14.127') @port = options.fetch(:port, 19302) end
Public Instance Methods
query_address()
click to toggle source
# File lib/stun/client.rb, line 88 def query_address payload = StunMessage.new(message_type: 0x0001).to_binary_s socket = UDPSocket.new socket.connect(@host, @port) socket.send(payload, 0, @host, @port) resp = socket.recv(1024) msg = StunMessage.read(resp) attr = msg[:attributes][:attribute_value] { id: "#{attr[:ip_a]}.#{attr[:ip_b]}.#{attr[:ip_c]}.#{attr[:ip_d]}", port: attr[:port] } end