Advertisement
Programist135

mcdns_client

Nov 27th, 2016
311
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local event = require("event")
  3. local string = require("string")
  4. local modem = component.modem
  5.  
  6. local dns_server = "8d039962-3451-48fd-8e41-c61ab1e59416"
  7. modem.open(19178)
  8. local lib = {}
  9.  
  10. function lib.get(dns_address)
  11.     if not string.find(dns_address, ".", 0, true) then
  12.         return false, "please type the zone"
  13.     end
  14.     repeat
  15.         modem.send(dns_server, 19178, "dns_request", dns_address)
  16.         data = {event.pull("modem_message")}
  17.     until data[3] == dns_server
  18.     -----
  19.     if data[6] == "dns_answer" and data[7] then
  20.         return data[7]
  21.     elseif data[6] == "dns_not" then
  22.         return false, "domain not exists"
  23.     end
  24. end
  25.  
  26. function lib.register(dns_address)
  27.     if not string.find(dns_address, ".", 0, true) then
  28.         return false, "please type the zone"
  29.     end
  30.     modem.send(dns_server, 19178, "dns_reg", dns_address)
  31.     local data = {event.pull("modem_message")}
  32.     if data[6] == "dns_success" then
  33.         return true
  34.     elseif data[6] == "dns_err" then
  35.         return false
  36.     end
  37. end
  38.  
  39. return lib
Advertisement
RAW Paste Data Copied
Advertisement