pandorrama

dns

Sep 12th, 2020 (edited)
1,283
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --TO INSTALL JUST EXECUTE: pastebin get UZiyN6Ub /usr/bin/dns.lua
  2.  
  3. local component = require ("component")
  4. local shell = require("shell")
  5. local resolve = require ("resolve")
  6. local network = require "network"
  7. local event = require "event"
  8. local computer = require "computer"
  9.  
  10. local args = shell.parse(...)
  11.  
  12.  
  13. -- get args
  14. local function get_args()
  15.   if #args < 2 and args[1] ~= "enumerate" then
  16.     io.write("Useage: dns <option> <device>\n")
  17.     os.exit()
  18.   end
  19.   return args[1], args[2]
  20. end
  21.  
  22. local function enumerate()
  23.   local clients = resolve.enumerate()
  24.   for i in pairs(clients) do
  25.     print(clients[i][1].." - "..clients[i][2])
  26.   end
  27. end
  28.  
  29. local function lookup(name)
  30.   local addr = resolve.lookup(name)
  31.   print(addr)
  32. end
  33.  
  34. local function rlookup(addr)
  35.   local name = resolve.rlookup(addr)
  36.   print(name)  
  37. end
  38.  
  39. local function ping(name)
  40.   address = resolve.lookup(name)
  41.   if address ~= "DNS_ERROR" then
  42.     shell.execute("ping "..address)
  43.   else
  44.     print("there was en DNS error. Probably you entered an invalid name")
  45.   end
  46. end
  47.  
  48. local option, device = get_args()
  49.  
  50. if option == "enumerate" then
  51.   enumerate()
  52. elseif option == "lookup" then
  53.   lookup(device)
  54. elseif option == "rlookup" then
  55.   rlookup(device)
  56. elseif option == "ping" then
  57.   ping(device)
  58. else -- (Default)
  59.   print ("Please choose a valid option")
  60. end
RAW Paste Data