Anda dapat membuat halaman dokumentasi untuk buat pada modul Scribunto ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
localp={} functionp._isIpV6(s) localdcolon,groups iftype(s)~="string" ors:len()==0 ors:find("[^:%x]")-- only colon and hex digits are legal chars ors:find("^:[^:]")-- can begin or end with :: but not with single : ors:find("[^:]:$") ors:find(":::") then returnfalse end s,dcolon=s:gsub("::",":") ifdcolon>1thenreturnfalseend-- 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==1andgroups<8)or(dcolon==0andgroups==8)) and(s:len()==0or(dcolon==1ands==":"))-- might be one dangling : if original ended with :: end functionp._isIpV4(s) localfunctionlegal(n)return(tonumber(n)or256)<256andnotn:match("^0%d")end-- in lua 0 is true! iftype(s)~="string"thenreturnfalseend localp1,p2,p3,p4=s:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$") returnlegal(p1)andlegal(p2)andlegal(p3)andlegal(p4) end functionp._isIp(s) returnp._isIpV4(s)and"4"orp._isIpV6(s)and"6" end functionp.isIpV6(frame)returnp._isIpV6(frame.args[1])and"1"or"0"end functionp.isIpV4(frame)returnp._isIpV4(frame.args[1])and"1"or"0"end functionp.isIp(frame)returnp._isIp(frame.args[1])or""end functionp.isIpOrRange(frame) -- {{#invoke:IPAddress|isIpOrRange|x}} → 'ip' (IPv4/IPv6) or 'range' (CIDR IPv4/IPv6) or '' (invalid) localmodip=require('Module:IP') locals=frame.args[1] localsuccess,ip=pcall(modip.IPAddress.new,s) ifsuccessthen return'ip' end success,ip=pcall(modip.Subnet.new,s) ifsuccessthen return'range' end return'' end returnp