Ruby’s core module, resolv, will allow you to easily parse raw DNS messages:

require 'resolv'

Resolv::DNS::Message.decode("\xE8\x84\x81\x80...")

msg.opcode
# => 0 

msg.question 
# => [[#<Resolv::DNS::Name: segv.me.>, Resolv::DNS::Resource::IN::A]]