Advertisement
GNT

Untitled

GNT
Sep 16th, 2021
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. local localAddress = ''
  22. for address, _ in component.list("modem", false) do
  23.   localAddress = address
  24.   break
  25. end
  26.  
  27. m.open(dnsport)
  28. gpu.setBackground(0x000000)
  29. gpu.setForeground(0x00ff00)
  30. term.clear()
  31.  
  32. print('Started DNS Server.')
  33. gpu.setForeground(0xff00ff)
  34. print('Listening and replying to requests on port '..dnsport)
  35. term.write('Address: ')
  36. gpu.setForeground(0xffffff)
  37. term.write(localAddress)
  38.  
  39. while true do
  40.   local _, _, from, port, _, command, param = event.pull('modem_message')
  41.   local command = string.lower(tostring(command))
  42.   local param = string.gsub(tostring(param), '\n', '')
  43.   gpu.setForeground(0xffff00)
  44.   print('Request from '..from)
  45.   if command == 'lookup' then
  46.     addr = tostring(dnsdb[param])
  47.     gpu.setForeground(0xffffff)
  48.     print('DNS Lookup: '.. param .. ' -> ' .. addr)
  49.     m.send(from, port, addr)
  50.   end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement