Advertisement
pepeknamornik

DNS check v1.0.0

Feb 23rd, 2022 (edited)
1,991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. local verze = "22.0223.R2"
  2. local tArgs = { ... }
  3. local idPC = os.getComputerID()
  4. local RamCesta = ("/C/system/RAM/dns_check.tmp")
  5.  
  6. if fs.exists("/C/system/.core/defmodem") then
  7.         local data = fs.open ("/C/system/.core/defmodem","r")
  8.         modemPos = data.readLine()
  9.         data.close()
  10.         if not modemPos then
  11.         modemPos = "offline"
  12.         end
  13.     else
  14.         modemPos = "offline"
  15.     end
  16.    
  17. if not (modemPos == "offline") then
  18.     modem = peripheral.wrap(modemPos)
  19.     modem.open(idPC)
  20.  
  21.     function zadat()
  22.         term.write("DNSserver ID: ")
  23.         srv_dns = tonumber(read())
  24.         term.write("Domain: ")
  25.         vyhledat(read())
  26.         zadat()
  27.     end
  28.  
  29.     function vyhledat(domain)
  30.         modem.transmit(tonumber(srv_dns),53,idPC)
  31.         modem.transmit(tonumber(srv_dns),54,domain)
  32.         local a = prijmout()
  33.        
  34.         local data = fs.open(RamCesta, "w") data.writeLine(a) data.close()
  35.         return a
  36.     end
  37.  
  38.     function prijmout ()
  39.  
  40.     timerRX = os.startTimer(5)
  41.         while true do
  42.         local event,p1,p2,p3,p4 = os.pullEvent()
  43.           if event == ("modem_message") then
  44.                     if (p3 == 55) then
  45.                         if p4 == false then
  46.                         return false
  47.                         else
  48.                         return p4
  49.                         end
  50.                     end
  51.           elseif event == "timer" then
  52.             error("Connection timed out!")
  53.             print()
  54.             return
  55.           end
  56.         end
  57.     end
  58.  
  59.     if #tArgs > 0 then
  60.             if (tArgs[1] == "get") then
  61.                 srv_dns = tonumber (tArgs[2])
  62.                 local a = vyhledat(tArgs[3])
  63.                 if (tArgs[4] == "write") then print(a) end
  64.                 return a
  65.                
  66.             else
  67.                 term.setBackgroundColor(colors.blue)
  68.                 term.setTextColor(colors.yellow)
  69.                 term.clear()
  70.                 term.setCursorPos(1,1)
  71.                 zadat()
  72.             end
  73.     else
  74.     zadat()
  75.     end
  76.    
  77. else
  78.     error("You must configure modem first")
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement