Advertisement
Guest User

dns.lua

a guest
Jun 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.51 KB | None | 0 0
  1. local computer=require("computer")
  2. local event=require("event")
  3.  
  4. local dns={}
  5.  
  6. function dns.ns(name, n)
  7.   local t1=os.time()  
  8.   local t2=os.time()
  9.   local k=true
  10.   local f=false
  11.   local addr=""
  12.   computer.pushSignal("dnsGet", name, n)
  13.   while k and not f do
  14.     t2=os.time()
  15.     if t1+120<t2 or t2<t1-99 then
  16.       k=false
  17.     end
  18.      e, addr, rname= event.pull(2, "dnsReq")  
  19.      if e~=nil and rname==name then    
  20.        f=true
  21.      end
  22.   end
  23.   if f then
  24.     return addr
  25.   else
  26.      return ""
  27.   end
  28. end
  29.  
  30. return dns
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement