Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
पमुख पत्त Pamukha patta
मन्तन ठान Mantana ṭhāna
नूतन विपरिणामेति Nūtana vipariṇāmeti
अनियता पत्त Aniyatā patta
अवस्सय Avassaya
अन्वेसना
खोज
Appearance
ददाति Dadāti
Create account
Log in
Personal tools
ददाति Dadāti
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:IPAddress
Add languages
Module
सम्भासनं
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Upload file
Page information
Get shortened URL
Download QR code
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
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) local function legal(n) return (tonumber(n) or 256) < 256 and not n:match("^0%d") end if type(s) ~= "string" then return false end local p1, p2, p3, p4 = s:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$") return legal(p1) and legal(p2) and legal(p3) and legal(p4) end function p._isIp(s) return p._isIpV4(s) and "4" or p._isIpV6(s) and "6" end function p._isIpOrRange(s) local modip = require('Module:IP') local success, ip = pcall(modip.IPAddress.new, s) if success then return 'ip' end success, ip = pcall(modip.Subnet.new, s) if success then return 'range' end return '' end local function input(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 function p.isIpV6(frame) return p._isIpV6(input(frame)) and "1" or "0" end function p.isIpV4(frame) return p._isIpV4(input(frame)) and "1" or "0" end function p.isIp(frame) return p._isIp(input(frame)) or "" end function p.isIpOrRange(frame) -- {{#invoke:IPAddress|isIpOrRange|x}} → 'ip' (IPv4/IPv6) or 'range' (CIDR IPv4/IPv6) or '' (invalid) return p._isIpOrRange(input(frame)) end return p
Summary:
By saving changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Preview page with this template
Wikidata entities used in this page
Module:IPAddress
: Sitelink, Description: en
Templates used on this page:
पटिरूप:Copied from English Wikipedia without documentation
(
edit
)
पटिरूप:Str rightc
(
edit
)
Module:IPAddress/doc
(
edit
)
Module:No globals
(
edit
)
Module:Ustring
(
edit
)
अन्वेसना
खोज
Editing
Module:IPAddress
Add languages
Add topic