Advertisement
Guest User

dnshook

a guest
Aug 23rd, 2014
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.74 KB | None | 0 0
  1. --[[
  2.     DNS Hook.
  3.     By Mitchfizz05. Licensed under the GNU General Pubic License v3.
  4. ]]
  5.  
  6. print("Hooking into the Rednet API...")
  7.  
  8. if not dns then
  9.     if fs.exists("dns") then
  10.         os.loadAPI("dns")
  11.     else
  12.         print("DNS API not found!")
  13.         return
  14.     end
  15. end
  16.  
  17. rawSend = rednet.send
  18.  
  19. -- Override the send function.
  20. function rednet.send(id, msg, protocol)
  21.     if type(id) == "string" then
  22.         -- A hostname was given. Preform a DNS lookup.
  23.         local resolvedID = dns.lookup(id)
  24.         if id == nil then
  25.             return false
  26.         end
  27.        
  28.         -- We have the ID - pass it into the generic rednet function.
  29.         rawSend(resolvedID, msg, protocol)
  30.         return true
  31.     else
  32.         -- An ID was given. Use the generic rednet function.
  33.         rawSend(id, msg, protocol)
  34.         return true
  35.     end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement