Modul:Internetszolgáltató
A modult a Modul:Internetszolgáltató/doc lapon tudod dokumentálni
local p = {}
local IPs -- lazily initialized
local function getArg(arg)
if type(arg) == table then
arg = require('Modul:Arguments').getArgs(arg)[1]
end
if type(arg) ~= 'string' then
arg = mw.title.getCurrentTitle().text
end
return arg
end
local function text(provider, static)
local statictexts = {
[true] = "statikus IP-cím",
[false] = "dinamikus IP-cím",
['?'] = "szöveg?"
}
local str = "'''" .. provider .. "'''"
if statictexts[static] then str = str .. " (" .. statictexts[static] .. ")" end
return str
end
local function validate(IP)
local v_table = mw.text.split(IP, '.', true)
local IPv6
if #v_table == 4 then
IPv6 = false
else
v_table = mw.text.split(IP, ':', true)
if #v_table == 8 then
IPv6 = true
else
return false
end
end
for i, v in pairs(v_table) do
local max
if(IPv6) then
if v == '' then
v = 0
else
v = tonumber(v, 16)
end
max = (16 ^ 4) - 1
else
v = tonumber(v, 10)
max = (2 ^ 8) - 1
end
if not v then return false end
if not ((0 <= v) and (v <= max)) then return false end
v_table[i] = v
end
return v_table, IPv6
end
function p.validate(IP)
IP = getArg(IP)
return not not validate(IP)
end
local function IPsum(v_table, IPv6)
local sum = 0
if IPv6 == nil then IPv6 = (#v_table == 8 and true) or false end
local times = (IPv6 and 16 ^ 4) or (2 ^ 8)
for n, v in pairs(v_table) do
sum = sum + (v * (times ^ (4-n) ) )
end
return sum
end
function p._IPcheck(IP)
--[[ fő függvény / main function
visszaadott értékek / returns:
* szöveges üzenet / message string
* szolgáltató neve / provider name
** string: ismert név / known name
** false: ismeretlen / unknown
** nil: hibás IP / malformed IP
* statikus-e / wheter it's static
** true: statikus / static
** false: dinamikus / dynamic
** nil: ismeretlen / unknown
]]
IP = getArg(IP)
local IPtable, IPv6 = validate(IP)
if not IPtable then return 'ez nem IP-cím', nil, nil end
IP = IPsum(IPtable, IPv6)
local provider = nil
if not IPs then
IPs = require('Modul:Internetszolgáltató/lista')
end
for _, v in pairs(IPs) do
if (IPsum(v[1]) <= IP) and (IP <= IPsum(v[2])) then provider = v[3]; static = v.static end
end
if provider then
return text(provider, static), provider, static
else return 'ismeretlen szolgáltató', false, nil
end
end
function p.IPcheck(IP)
-- wikiszövegbe csak a szöveges üzenetet adjuk vissza
-- return only message string to wikitext
return (p._IPcheck(IP))
end
return p