summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/NetworkTest
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-01-29 11:09:56 +0100
committerMattes D <github@xoft.cz>2015-02-04 08:40:52 +0100
commit17498a97a289119debdb651ab898ddea99e86ff9 (patch)
tree04f103b0c0f5d120cec59756618bcafeafb53cb2 /MCServer/Plugins/NetworkTest
parentNetworkTest plugin: Added cNetwork:Connect test code. (diff)
downloadcuberite-17498a97a289119debdb651ab898ddea99e86ff9.tar
cuberite-17498a97a289119debdb651ab898ddea99e86ff9.tar.gz
cuberite-17498a97a289119debdb651ab898ddea99e86ff9.tar.bz2
cuberite-17498a97a289119debdb651ab898ddea99e86ff9.tar.lz
cuberite-17498a97a289119debdb651ab898ddea99e86ff9.tar.xz
cuberite-17498a97a289119debdb651ab898ddea99e86ff9.tar.zst
cuberite-17498a97a289119debdb651ab898ddea99e86ff9.zip
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/NetworkTest/Info.lua21
-rw-r--r--MCServer/Plugins/NetworkTest/NetworkTest.lua42
2 files changed, 63 insertions, 0 deletions
diff --git a/MCServer/Plugins/NetworkTest/Info.lua b/MCServer/Plugins/NetworkTest/Info.lua
index 6bb639860..8c2604e31 100644
--- a/MCServer/Plugins/NetworkTest/Info.lua
+++ b/MCServer/Plugins/NetworkTest/Info.lua
@@ -36,6 +36,27 @@ g_PluginInfo =
},
}, -- ParameterCombinations
}, -- client
+
+ lookup =
+ {
+ HelpString = "Looks up the IP addresses corresponding to the given hostname (google.com by default)",
+ Handler = HandleConsoleNetLookup,
+ ParameterCombinations =
+ {
+ {
+ Params = "",
+ Help = "Looks up the IP addresses of google.com.",
+ },
+ {
+ Params = "Hostname",
+ Help = "Looks up the IP addresses of the specified hostname.",
+ },
+ {
+ Params = "IP",
+ Help = "Looks up the canonical name of the specified IP.",
+ },
+ },
+ }, -- lookup
}, -- Subcommands
}, -- net
},
diff --git a/MCServer/Plugins/NetworkTest/NetworkTest.lua b/MCServer/Plugins/NetworkTest/NetworkTest.lua
index 1a24d4865..30f34c879 100644
--- a/MCServer/Plugins/NetworkTest/NetworkTest.lua
+++ b/MCServer/Plugins/NetworkTest/NetworkTest.lua
@@ -61,3 +61,45 @@ end
+
+function HandleConsoleNetLookup(a_Split)
+ -- Get the name to look up:
+ local Addr = a_Split[3] or "google.com"
+
+ -- Create the callbacks "personalised" for the host:
+ local Callbacks =
+ {
+ OnNameResolved = function (a_Hostname, a_IP)
+ LOG(a_Hostname .. " resolves to " .. a_IP)
+ end,
+
+ OnError = function (a_Query, a_ErrorCode, a_ErrorMsg)
+ LOG("Failed to retrieve information for " .. a_Query .. ": " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
+ assert(a_Query == Addr)
+ end,
+
+ OnFinished = function (a_Query)
+ LOG("Resolving " .. a_Query .. " has finished.")
+ assert(a_Query == Addr)
+ end,
+ }
+
+ -- Queue both name and IP DNS queries;
+ -- we don't distinguish between an IP and a hostname in this command so we don't know which one to use:
+ local res = cNetwork:HostnameToIP(Addr, Callbacks)
+ if not(res) then
+ LOGWARNING("cNetwork:HostnameToIP call failed immediately")
+ return true
+ end
+ res = cNetwork:IPToHostname(Addr, Callbacks)
+ if not(res) then
+ LOGWARNING("cNetwork:IPToHostname call failed immediately")
+ return true
+ end
+
+ return true, "DNS query has been queued."
+end
+
+
+
+