Module:IPAddress
- العربية
- Авар
- Azərbaycanca
- تۆرکجه
- বাংলা
- Беларуская (тарашкевіца)
- भोजपुरी
- Ελληνικά
- فارسی
- Français
- ગુજરાતી
- 한국어
- Ilokano
- Latviešu
- Magyar
- മലയാളം
- မြန်မာဘာသာ
- Nederlands
- 日本語
- Нохчийн
- Norsk bokmål
- Oʻzbekcha / ўзбекча
- पालि
- پښتو
- Português
- Русский
- සිංහල
- Simple English
- Slovenščina
- کوردی
- Српски / srpski
- Tagalog
- தமிழ்
- တႆး
- ไทย
- Українська
- اردو
- Tiếng Việt
- 文言
- 粵語
- 中文
Appearance
From Wikipedia, the free encyclopedia
[画像:Warning] This Lua module is used in MediaWiki:Newarticletext and MediaWiki:Blockedtext , and on approximately 205,000 pages.
Changes to it can cause immediate changes to the Wikipedia user interface.
To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them.
Changes to it can cause immediate changes to the Wikipedia user interface.
To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them.
This module can only be edited by administrators because it is transcluded onto one or more cascade-protected pages.
Functions are not "local", so other modules can require this module and call them directly. We return an object with 3 small stub functions to call the real ones so that the functions can be called from templates also.
Only dotted decimal notation for IPv4 supported. Does not support dotted hexadecimal, dotted octal, or single-number formats (see IPv4#Address_representations).
Unit tests at Module:IPAddress/testcases
The above documentation is transcluded from Module:IPAddress/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Subpages of this module.
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 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._isIpV4Range(s) returnp._isIpV4(s:gsub("/%d+$",""))and(p._isIpOrRange(s)=='range') end functionp._isIpV6Range(s) returnp._isIpV6(s:gsub("/%d+$",""))and(p._isIpOrRange(s)=='range') end functionp._isIpOrRange(s) localmodip=require('Module:IP') localsuccess,ip=pcall(modip.IPAddress.new,s) ifsuccessthen return'ip' end success,ip=pcall(modip.Subnet.new,s) ifsuccessthen return'range' end return'' end localfunctioninput(frame) -- Return input parameter after replacing any of following directional markers. -- LRM : LEFT-TO-RIGHT MARK (U+200E) : hex e2 80 8e = 226 128 142 -- LRE : LEFT-TO-RIGHT EMBEDDING (U+202A) : hex e2 80 aa = 226 128 170 -- PDF : POP DIRECTIONAL FORMATTING (U+202C) : hex e2 80 ac = 226 128 172 -- This is required for MediaWiki:Blockedtext message. return(frame.args[1]or''):gsub('226円128円[142円170円172円]',' ')-- replace LRM, LRE, PDF with space delimiter end functionp.isIpV6(frame)returnp._isIpV6(input(frame))and"1"or"0"end functionp.isIpV4(frame)returnp._isIpV4(input(frame))and"1"or"0"end functionp.isIpV6Range(frame)returnp._isIpV6Range(input(frame))and"1"or"0"end functionp.isIpV4Range(frame)returnp._isIpV4Range(input(frame))and"1"or"0"end functionp.isIp(frame)returnp._isIp(input(frame))or""end functionp.isIpOrRange(frame) -- {{#invoke:IPAddress|isIpOrRange|x}} → 'ip' (IPv4/IPv6) or 'range' (CIDR IPv4/IPv6) or '' (invalid) returnp._isIpOrRange(input(frame)) end returnp