View source for Module:IPAddress
You do not have permission to edit this page, for the following reasons:
You can view and copy the source of this page.
local p = {}
function p._isIpV6(s)
local dcolon, groups
if type(s) ~= "string"
or s:len() == 0
or s:find("[^:%x]") -- only colon and hex digits are legal chars
or s:find("^:[^:]") -- can begin or end with :: but not with single :
or s:find("[^:]:$")
or s:find(":::")
then
return false
end
s, dcolon = s:gsub("::", ":")
if dcolon > 1 then return false end -- at most one ::
s = s:gsub("^:?", ":") -- prepend : if needed, upper
s, groups = s:gsub(":%x%x?%x?%x?", "") -- remove valid groups, and count them
return ( (dcolon == 1 and groups < 8) or (dcolon == 0 and groups == 8) )
and ( s:len() == 0 or (dcolon == 1 and s == ":") ) -- might be one dangling : if original ended with ::
end
function p._isIpV4(s)
000
1:0
Template used on this page:
Return to Module:IPAddress.