iprangeblocker needed
 

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

iprangeblocker needed

Started by bliskner, 27 May, 2004, 12:01:32

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bliskner

hi i need an ip range blocker for PtokaX however the only onesi can find all expect you to add the ranges to be blocked - as i am on a university network where we get charged for traffic off the network we want a hub thet only supports local users - however the hub cannont itself be on the network. so what i need is an ip range blocker that at base level blocks all ips - yet allows me to add specific ranges which are not blocked. can this be done? i really don't want to have to go thru putting in 256 ranges in to the perma ban list on PtokaX only to have someone delte the list if they accidentally (or not as the case may be) clear the ban list.

can anyone help?

Jaras

#1
function Is2ndIPHigher( IP1, IP2 )
	local _,_,dec1 = strfind( IP1, "^(%d+)%.?" )
	local _,_,dec2 = strfind( IP2, "^(%d+)%.?" )
	if not( strfind( IP1, ".", 1, 1 ) ) or not( strfind( IP2, ".", 1, 1 ) ) or ( dec1 ~= dec2 ) then
		return tonumber( dec1 ) <= tonumber( dec2 )
	else
		IP1 = strsub( IP1, strlen( dec1 ) + 2 )
		IP2 = strsub( IP2, strlen( dec2 ) + 2 )
		return Is2ndIPHigher( IP1, IP2 )
	end
end

this function returns true if IP1 <= IP2, else it returns false, so when you do:
IPRangeFrom = "66.66.66.66"
IPRangeTo = "77.77.77.77"

function IsIPInRange( curUser )
     return ( Is2ndIPHigher( IPRangeFrom, curUser.sIP ) ) and ( Is2ndIPHigher( curUser.sIP, IPRangeTo ) )
end

IsIPInRange will return true when curUser.sIP is between 66.66.66.66 and 77.77.77.77.

edit: thought that i don't have time, but had some and here - it SHOULD work:
BotName = "IPRangeBlocker"

Message = "***Sorry but your IP isn't allowed here..."

--//Note that IPRangeFrom and IPRangeTo must've same size, so first range is 11.11.11.11 to 15.15.15.15 and so on
IPRangeFrom = { 
	[1]="11.11.11.11",
	[2]="22.22.22.22",
	[3]="33.33.33.33",
}

IPRangeTo = {
	[1]="15.15.15.15",
	[2]="25.25.25.25",
	[3]="35.35.35.35",
}


function Is2ndIPHigher( IP1, IP2 )
	local _,_,dec1 = strfind( IP1, "^(%d+)%.?" )
	local _,_,dec2 = strfind( IP2, "^(%d+)%.?" )
	if not( strfind( IP1, ".", 1, 1 ) ) or not( strfind( IP2, ".", 1, 1 ) ) or ( dec1 ~= dec2 ) then
		return tonumber( dec1 ) <= tonumber( dec2 )
	else
		IP1 = strsub( IP1, strlen( dec1 ) + 2 )
		IP2 = strsub( IP2, strlen( dec2 ) + 2 )
		return Is2ndIPHigher( IP1, IP2 )
	end
end

function IsIPInRange( userIP )
	local inRange = 1
	for i,v in IPRangeFrom do
		inRange = ( inRange ) and ( ( Is2ndIPHigher( v, userIP ) ) and ( Is2ndIPHigher( userIP, IPRangeTo[i] ) ) )
	end
	return inRange
end

function NewUserConnected( curUser )
	if not IsIPInRange( curUser.sIP ) then
		curUser:SendData( BotName, Message )
		curUser:Disconnect()
	end
end

function Main()
	frmHub:RegBot( BotName )
end

SMF spam blocked by CleanTalk