diff options
Diffstat (limited to 'src/actions.lua')
| -rw-r--r-- | src/actions.lua | 104 |
1 files changed, 102 insertions, 2 deletions
diff --git a/src/actions.lua b/src/actions.lua index 007d978..370f138 100644 --- a/src/actions.lua +++ b/src/actions.lua @@ -56,7 +56,7 @@ function fetchservice () -- check length if not (#arg == 3) then - help.fetchservice () + help.fetchservice() return end @@ -99,9 +99,109 @@ function fetchservice () end +-- misc: dns +function dns () + + -- check length + if not (#arg == 3) then + + help.dns() + return + + end + + -- get server name + local server = Servers[arg[2]] + + if not server then + + print("\nE> Error: server not found.\n") + return + + end + + -- repeat requests till hostname found or no more services + local looking = true + local foundrecord + local index = 0 + + while looking do + + -- convert number to hex + local hexIndex = string.format("%04x", index) + + -- send request + local request = PawSD.Verbs.FETCH_SERVICE .. server.keyalg .. "0020" .. server.key .. hexIndex + local response = send(server, request) + + -- check response + local valid = pawsd.response.validate(response) + + if not valid then + + looking = false + return + + end + + -- get records + local records = pawsd.service.records.all(response) + + -- check each tag & record + for recordindex = 1, #records, 1 do + for recordtagindex = 1, #records[recordindex], 1 do + + -- get tag + local tag = records[recordindex][recordtagindex] + + -- check if "dns-style hostname" + if tag.types.high == "EDCC1A0A8817F0F6" and tag.types.low == "E8ED44A7A4760A51" then + + -- strip index unicode char & compare to wanted hostname + local check = string.fromhex(string.sub(tag.value, 1, -3)) == arg[3] + + if check then + + looking = false + foundrecord = records[recordindex] + + end + end + end + end + + index = index + 1 + + end + + -- if hostname has been found + if foundrecord then + for tagindex = 1, #foundrecord, 1 do + + local tag = foundrecord[tagindex] + + -- get ipv4 address + if tag.types.low == "DF4E01093265D87B" then + + -- build address + local address = { + tonumber(string.sub(tag.value, 1, 2), 16), + tonumber(string.sub(tag.value, 3, 4), 16), + tonumber(string.sub(tag.value, 5, 6), 16), + tonumber(string.sub(tag.value, 7, 8), 16) + } + + print("I> " .. table.concat(address, ".")) + end + end + end +end + -- return return { echo = echo, - fetchservice = fetchservice + fetchservice = fetchservice, + + dns = dns } |
