Jump to content

Module:Sandbox/Johnuniq/ip

From Wikipedia, the free encyclopedia

This is the current revision of this page, as edited by Johnuniq (talk | contribs) at 01:46, 21 June 2018 (catch error from Module:IP). The present address (URL) is a permanent link to this version.

(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
-- Try catching error from [[Module:IP]] from merge proposal at
-- Wikipedia:Templates_for_discussion/Log/2018_June_19#Module:IP
-- See results on talk page.

local IP = require('Module:IP')
local IPAddress = IP.IPAddress

local function main(frame)
	local results = {}
	for i, ipstr in ipairs({
		'',
		'junk',
		'1.2.3.255',
		'1.2.3.256',
		'1:2:3:4:1FFF:ffff:ffff:ffff',
		'1:2:3:4:1800::',
		'0.0.0.0',
		'0:0:0:0:0:0:0:0',
		'1::ffff:ffff',
		'1::fffff:ffff',
		'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
	}) do
		local success, ip = pcall(IPAddress.new, ipstr)
		table.insert(results,
				'*"' .. ipstr .. '" is ' ..
				(success and (ip:isIPv4() and 'IPv4' or 'IPv6') or 'invalid')
			)
	end
	return table.concat(results, '\n')
end

return { main = main }