Advertisement
Guest User

dnsserver.lua

a guest
Jan 21st, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. -- DNS Server by Codian
  2. -- Add DNS'es to the table and their respective ID's
  3. -- The server will listen on the specified port with "dnsport"
  4.  
  5.  
  6. local component = require('component')
  7. local event = require('event')
  8. local m = component.modem
  9. local gpu = component.gpu
  10. local term = require('term')
  11.  
  12. -- Listening and replying port
  13. local dnsport = 42069
  14.  
  15. -- DNS Table
  16. -- ['dns name'] = 'network card address'
  17. dnsdb = {
  18.   ['example'] = '00000000-0000-0000-0000-000000000000'
  19. }
  20.  
  21. m.open(dnsport)
  22. gpu.setBackground(0x000000)
  23. gpu.setForeground(0x00ff00)
  24. term.clear()
  25.  
  26. print('Started DNS Server.')
  27. gpu.setForeground(0xff00ff)
  28. print('Listening and replying to requests on port '..dnsport)
  29.  
  30. while true do
  31.   local _, _, from, port, _, command, param = event.pull('modem_message')
  32.   local command = string.lower(tostring(command))
  33.   local param = string.gsub(tostring(param), '\n', '')
  34.   gpu.setForeground(0xffff00)
  35.   print('Request from '..from)
  36.   if command == 'lookup' then
  37.     addr = tostring(dnsdb[param])
  38.     gpu.setForeground(0xffffff)
  39.     print('DNS Lookup: '.. param .. ' -> ' .. addr)
  40.     m.send(from, port, addr)
  41.   end
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement