Any easy way to detect if an IP is a valid IPv6 and also if it is valid, how to parse it to get the byte array?
Currently using ZeroBrane Studio IDE and the integrated Lua version is 5.1
Any easy way to detect if an IP is a valid IPv6 and also if it is valid, how to parse it to get the byte array?
Currently using ZeroBrane Studio IDE and the integrated Lua version is 5.1
As part of the answer on how to check if the IPv6 address is valid, the string is parsed into a table, which you can use for your purposes:
-- assuming you already check that the string has IPv6 format
local ip = "1050:0000:0000:0000:0005:0600:300c:326b"
local chunks = {ip:match(("([a-fA-F0-9]*):"):rep(8):gsub(":$","$"))}
print(table.concat(chunks, ":"))