PtokaX forum

Development Section => LUA & PtokaX-Scripting-Interface => Topic started by: c h i l l a on 25 February, 2004, 19:40:39

Title: DeComputeIP
Post by: c h i l l a on 25 February, 2004, 19:40:39
here is one way to do so..

function DeComputeIP(cIP)
local ip1 = floor(cIP/16777216)  
local ip2 = floor(mod(cIP,16777216)/65536)
local ip3 = floor(mod(mod(cIP,16777216),65536)/256)
local ip4 = floor(mod(mod(mod(cIP,16777216),65536),256))
return (ip1.."."..ip2.."."..ip3.."."..ip4)
end
Title:
Post by: NightLitch on 25 February, 2004, 20:32:54
What is this good for Chilla ?
Title:
Post by: NightLitch on 25 February, 2004, 20:33:49
mean DeComputeIP

is it the oposite to ComputeIP ?
Title:
Post by: Skrollster on 25 February, 2004, 21:07:12
chilla, wouldn't

function DeComputeIP(cIP)
local i,j
i = mod(cIP,16777216)
j = mod(i,65536)
local ip1 = floor(cIP/16777216)  
local ip2 = floor(i/65536)
local ip3 = floor(j/256)
local ip4 = floor(mod(j,256))
return (ip1.."."..ip2.."."..ip3.."."..ip4)
end

be a bit faster??

or maybe

function DeComputeIP(cIP)
local i = mod(cIP,16777216)
local j = mod(i,65536)
return (floor(cIP/16777216).."."..floor(i/65536).."."..floor(j/256).."."..floor(mod(j,256)))
end
Title:
Post by: c h i l l a on 25 February, 2004, 21:20:57
not tested, but looks like, it was my first try :p ;)

oh an nightlitch, sure, there is also a ComputeIP func,

function ComputeIP(curIP)
local _,_,a,b,c,d = strfind(curIP, "^(%d+)%.(%d+)%.(%d+)%.(%d+)$")
return a*16777216 + b*65536 + c*256 + d
end
Title:
Post by: NightLitch on 25 February, 2004, 21:30:12
That I know. But nice. Maybe start playing with this in my new IP-NXS-RANGER. Without checking your LIS.

know you have it there. have seen the "ranges"... :-)
Title:
Post by: c h i l l a on 25 February, 2004, 21:42:31
yeeaa, tell me when your done.
Will then add it to IP.BATTLE :)
Title:
Post by: NightLitch on 25 February, 2004, 21:56:29
Well I already have one created.

But I don't think is so fast Or It could be.

Can post it l8r.
Title:
Post by: Skrollster on 25 February, 2004, 22:09:42
I think this one can be quite handy if you wanted to precompute the ip range and some times want to check them..
Title:
Post by: NotRabidWombat on 25 February, 2004, 22:17:37
How about:
function Int64ToIPString(iIP)
   local sRet = "";
   for j = 0, j < 4, 1 do
      if( j ~= 0) then sRet = "." .. sRet; end
      sRet = mod(iIP, 256) .. sRet;
      iIP = floor(iIP / 256);
   end

   return sRet;
end

-NotRabidWombat
Title:
Post by: Skrollster on 26 February, 2004, 08:52:24
Quite nice solution, but i don't beleve that is would be faster ;)
Title:
Post by: NotRabidWombat on 26 February, 2004, 15:05:46
Division takes a while if you use really big numbers. And you push more variables on the stack. Someone should do a time comparison and then the best one is accepted.

I admit I can make this one REALLY fast if I had the bitwise functions of Lua 5.0.

-NotRabidWombat
Title:
Post by: Skrollster on 26 February, 2004, 17:01:35
It wouldn't hurt if ptaczek did change over from lua 4.0 to 5.0 imho, but i think it is more intresting to get the new betas out....