DeComputeIP
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

DeComputeIP

Started by c h i l l a, 25 February, 2004, 19:40:39

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

c h i l l a

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

NightLitch

What is this good for Chilla ?
//NL

NightLitch

mean DeComputeIP

is it the oposite to ComputeIP ?
//NL

Skrollster

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

c h i l l a

#4
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

NightLitch

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"... :-)
//NL

c h i l l a

yeeaa, tell me when your done.
Will then add it to IP.BATTLE :)

NightLitch

Well I already have one created.

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

Can post it l8r.
//NL

Skrollster

I think this one can be quite handy if you wanted to precompute the ip range and some times want to check them..

NotRabidWombat

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


I like childish behavior. Maybe this post will be deleted next.

Skrollster

Quite nice solution, but i don't beleve that is would be faster ;)

NotRabidWombat

#11
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


I like childish behavior. Maybe this post will be deleted next.

Skrollster

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....

SMF spam blocked by CleanTalk