Skip to content

Instantly share code, notes, and snippets.

@clicube
Created July 14, 2013 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clicube/5993268 to your computer and use it in GitHub Desktop.
Save clicube/5993268 to your computer and use it in GitHub Desktop.
require 'socket'
require 'thread'
query = <<QUERY
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MAN: "ssdp:discover"
MX: 3
ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1
QUERY
sock = UDPSocket.open
sock.bind("0.0.0.0",1900)
thread = Thread.new do
loop do
puts sock.recv(65535)
end
end
sock.send(query, 0, "239.255.255.250", 1900)
sleep 1
thread.kill
sock.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment