Author Topic: iprangeblocker needed  (Read 1353 times)

0 Members and 1 Guest are viewing this topic.

Offline bliskner

  • Junior Member
  • **
  • Posts: 22
  • Karma: +0/-0
iprangeblocker needed
« on: 27 May, 2004, 12:01:32 »
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?

PtokaX forum

iprangeblocker needed
« on: 27 May, 2004, 12:01:32 »

Offline Jaras

  • Member
  • ***
  • Posts: 37
  • Karma: +0/-0
(No subject)
« Reply #1 on: 27 May, 2004, 12:54:58 »
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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
« Last Edit: 27 May, 2004, 13:33:55 by Jaras »

PtokaX forum

(No subject)
« Reply #1 on: 27 May, 2004, 12:54:58 »