I want to add Domain Verification to this function:
GetType = function(ip)
local Split = function(s,sep)
local t={};i=1
for str in string.gmatch(s,"([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
local R = {ERROR=0,IPV4=1,IPV6=2,DOMAIN=3,STRING=4}
if type(ip) ~= "string" then return R.ERROR end
local chunks = {ip:match("(%d+)%.(%d+)%.(%d+)%.(%d+)")}
if
for _,v in pairs(chunks) do
if tonumber(v) > 255 then return R.STRING end
end
return R.IPV4
end
local chunks = {ip:match(("([a-fA-F0-9]*):"):rep(8):gsub(":$","$"))}
if
for _,v in pairs(chunks) do
if
end
return R.IPV6
end
-- Domain check
-- Ensuring only alphanumeric characters and . and -
-- Ensuring no --
-- Ensuring - is not at the start or end of part
-- Ensuring there is more than one part
if string.gsub(ip,"[%w%-%.]","") ~= "" then return R.STRING end
if string.find(ip,'--',1,true) ~= nil then return R.STRING end
local t = Split(ip,"%.")
if
for i,v in pairs(t) do
if string.find(t[i],'-',1,true) == 1 or string.find(t[i],'-',
end
return R.DOMAIN
end
This works well with IPV4 / 6, but I lost a bit how to do domain verification, so the questions are:
What is the best method to test?
Do I have everything to check the correctness?
source
share