aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/actions.lua104
-rw-r--r--src/help.lua16
-rw-r--r--src/pawsd/send.lua3
3 files changed, 120 insertions, 3 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
}
diff --git a/src/help.lua b/src/help.lua
index 7f0c82d..cf6b25e 100644
--- a/src/help.lua
+++ b/src/help.lua
@@ -14,6 +14,9 @@ function main ()
print("---*> 0000 - echo")
print("\n---*> 0001 - fetchservice\n")
+ print("\n*> Other Utils:")
+ print("---*> dns")
+
end
-- 0000: echo
@@ -36,11 +39,22 @@ function fetchservice ()
end
+-- misc: look up dns
+function dns ()
+
+ print("\nDNS Lookup - Look up the IP address associated with a hostname.")
+
+ print("\n*> Usage:")
+ print("\n lua selenepaw.lua dns <server name> <hostname>\n")
+end
+
-- return
return {
main = main,
echo = echo,
- fetchservice = fetchservice
+ fetchservice = fetchservice,
+
+ dns = dns
}
diff --git a/src/pawsd/send.lua b/src/pawsd/send.lua
index 156664d..3492ed1 100644
--- a/src/pawsd/send.lua
+++ b/src/pawsd/send.lua
@@ -35,6 +35,9 @@ function send (server, data)
end
+ -- close client
+ client:close()
+
-- return response
return response