Skip to content

Instantly share code, notes, and snippets.

@michenriksen
Last active August 29, 2015 14:07
Show Gist options
  • Save michenriksen/f8374366620198cd07a1 to your computer and use it in GitHub Desktop.
Save michenriksen/f8374366620198cd07a1 to your computer and use it in GitHub Desktop.
Script to view Firechat broadcast messages
# Read more about the issue here: http://breizh-entropy.org/~nameless/random/posts/firechat_and_nearby_communication/
require 'socket'
require 'openssl'
require 'json'
require 'cgi'
FIRECHAT_HOST = '209.237.236.194'
FIRECHAT_PORT = 4176
sock = TCPSocket.new(FIRECHAT_HOST, FIRECHAT_PORT)
ctx = OpenSSL::SSL::SSLContext.new
ctx.set_params(:verify_mode => OpenSSL::SSL::VERIFY_NONE)
print "[*] Connecting to #{FIRECHAT_HOST}:#{FIRECHAT_PORT}... "
OpenSSL::SSL::SSLSocket.new(sock, ctx).tap do |socket|
socket.sync_close = true
socket.connect
puts "connected!\n\n"
while line = socket.gets
message = JSON.load(line.strip)
translation_link = "https://translate.google.com/#auto/en/#{CGI.escape(message['msg'])}"
puts "[#{Time.at(message['st']).strftime('%H:%M:%S')}] " +
"<\033[1m\033[34m#{message['user']}\033[0m\033[22m(#{message['name']})" +
"@\033[1m\033[36m#{message['loc'] || 'Unknown'}\033[0m\033[22m> " +
"\033[1m\033[37m#{message['msg']}\033[0m\033[22m \033[2m(#{translation_link})\033[22m"
end
socket.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment