Content deleted Content added
→isIpOrRange: new section |
|||
Line 52:
--[[User:Davidgothberg|David Göthberg]] ([[User talk:Davidgothberg|talk]]) 22:22, 27 December 2019 (UTC)
== isIpOrRange ==
@[[User:L235|KevinL]]: Per the discussion at [[User talk:Johnuniq#Template help?|my talk]] ([[Special:PermanentLink/993870706#Template help?|permalink]]), I have added a function you can use to [[Module:IPAddress/sandbox]]. Once you're happy with it, it can be moved to [[Module:IPAddress]]. I guess that is the best place. This module is full-protected which might suit your purposes.
The function returns 'ip' if the input is an IPv4 or IPv6 address, or 'range' if a CIDR IPv4 or IPv6 range. Otherwise it returns an empty string. That should make it easy for testing with #if. Some examples of how to call it follow.
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange|1.2.3.4}}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange|1.2.3.4}}
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange| 1.2.3.4 }}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange| 1.2.3.4 }}
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange|1.2.3.0/24}}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange|1.2.3.0/24}}
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange|2606:6000:610a:9000:9df6:cc8d:592b:1ae}}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange|2606:6000:610a:9000:9df6:cc8d:592b:1ae}}
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange|2606:6000:610a:9000::/64}}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange|2606:6000:610a:9000::/64}}
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange}}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange}}
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange|}}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange|}}
*<code><nowiki>{{#invoke:IPAddress/sandbox|isIpOrRange|Jimbo}}</nowiki></code> → {{#invoke:IPAddress/sandbox|isIpOrRange|Jimbo}}
The second example shows that leading/trailing whitespace is ignored. If some other way of calling it is wanted, or some change, let me know. I'm posting here to alert others watching this page. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 09:20, 14 December 2020 (UTC)
|