–IP地址补全
172.0.0.1 —> 172.000.000.001
local ip = '172.0.0.1';
local aa = '.';
function mysplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
function buweiIP(IP)
local result = mysplit(ip,".");
for k,v in pairs(result) do
local _len = string.len(v);
if _len == 2 then
v = '0'..v;
elseif _len == 1 then
v = '00'..v;
end
aa = aa..'.'..v;
end
return aa
end
bb = string.sub(buweiIP(ip),3)
print(bb)
本文介绍了一个简单的Lua脚本,用于将IP地址格式化为统一的八位数字表示形式。通过定义函数实现对输入IP地址各部分的零填充,确保每个部分都由三位数字组成。
517

被折叠的 条评论
为什么被折叠?



