pandorrama

resolve

Sep 10th, 2020 (edited)
924
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --TO INSTALL JUST EXECUTE: pastebin get iViYcDWQ /usr/lib/resolve.lua
  2.  
  3. local component = require("component")
  4. local network = require "network"
  5. local shell = require("shell")
  6. local dns_client = require("dns_client")
  7.  
  8.  
  9. --local component = require("component")
  10. local modem = component.modem
  11. local event = require("event")
  12. local ttf = require("tableToFile")
  13.  
  14. local settingsLocation = "/dns/data/DNS_SETTINGS.cfg"
  15. local settings = ttf.load(settingsLocation)
  16.  
  17.  
  18. local resolve = {}
  19.  
  20.  
  21. function  resolve.enumerate()
  22.   local hosts = {}
  23.   for interface in pairs(network.info.getInfo().interfaces) do
  24.     for i, host in ipairs(network.info.getArpTable(interface)) do
  25.       if (host ~= "localhost") then
  26.         hosts[i] = {}
  27.         hosts[i][1] = host
  28.         hosts[i][2] = resolve.rlookup(host)
  29.       end
  30.     end
  31.   end
  32.   return hosts
  33. end
  34.  
  35. function resolve.lookup(name)
  36.   see = dns_client.start()
  37.   addr, err = dns_client.lookup(name)
  38.   if (addr) then
  39.     dns_client.stop()
  40.     return addr
  41.   else
  42.     dns_client.stop()
  43.     return "DNS_ERROR"--..tostring(err)
  44.   end
  45. end
  46.  
  47. function resolve.rlookup(addr)
  48.   dns_client.start()
  49.   local name, err = dns_client.rlookup(addr)
  50.   if (name) then
  51.     dns_client.stop()
  52.     return name
  53.   else
  54.     dns_client.stop()
  55.     return "DNS_ERROR"--..tostring(err)
  56.   end
  57. end
  58.  
  59. return resolve
RAW Paste Data