1function _M.ipToInt( str ) 2 local num = 0 3 if str and type(str)=="string" then 4 local o1,o2,o3,o4 = str:match("(%d+)%.(%d+)%.(%d+)%.(%d+)" ) 5 num = 2^24*o1 + 2^16*o2 + 2^8*o3 + o4 6 end 7 return num 8end 9-- inter to ip 10function _M.intToIp( n ) 11 if n then 12 n = tonumber(n) 13 local n1 = math.floor(n / (2^24)) 14 local n2 = math.floor((n - n1*(2^24)) / (2^16)) 15 local n3 = math.floor((n - n1*(2^24) - n2*(2^16)) / (2^8)) 16 local n4 = math.floor((n - n1*(2^24) - n2*(2^16) - n3*(2^8))) 17 return n1.."."..n2.."."..n3.."."..n4 18 end 19 return "0.0.0.0" 20end
Lua ip to int 和 int to ip
Stella981
2021-10-11
1334 0 0
点赞
收藏
评论区
加载中...