Good IP Range blocker? - Page 2
 

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

Good IP Range blocker?

Started by BlazeXxX, 27 October, 2003, 01:34:08

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

tezlo

ok here goes..
only unregistered users get checked
and theres no need for a txt file
-- easyranger
-- tezlo

ipRanges = {}
regUsers = {}

denyMsg = " You dont belong here."

function compute(ip)
	local s, e, a, b, c, d = strfind(ip, "^(%d+).(%d+).(%d+).(%d+)$")
	if s then return a*16777216 + b*65536 + c*256 + d end return 0
end

function checkrange(table, ip)
	return foreachi(table, function(id, tmp)
		if (%ip >= tmp[1]) and (%ip <= tmp[2]) then return tmp end
	end)
end

function load(name, data)
	ipRanges[name] = ipRanges[name] or {}
	gsub(data, "(%S+) %- (%S+)", function(s, e)
		s, e = compute(s), compute(e)
		tinsert(ipRanges[%name], { s, e })
	end)
end

function Main()
	local f, file
	f = openfile("ranger.dat", "r") assert(f, "ranger.dat")
	file = read(f, "*a") closefile(f) gsub(file, "%[(%S+)%]([%c%d%s%-%.]+)", load)
	f = openfile("../RegisteredUsers.dat", "r") assert(f, "RegisteredUsers.dat")
	file = read(f, "*a") closefile(f) gsub(file, "(%S-)%|%C+%|%d+%c", function(nick) regUsers[nick] = 1 end)
end

function NewUserConnected(user)
	if regUsers[user.sName] then return end
	local ip, block = compute(user.sIP)
	for name, range in ipRanges do
		if checkrange(range, ip) then block = name break end
	end if block then
		SendToOps("Hub-Security", user.sName.." ["..user.sIP.."] disconnected because.. "..block)
		user:SendData(denyMsg) user:Disconnect()
	end
end

btw.. ive tested both algos for speed
and mine (ptaczek's) came out about 30x faster :o

BlazeXxX

Thx Tezlo :d let me try it and see :)

klownietklowniet

How did you do that test tezlo... and 30 times faster? :D
[ > DC - UniteD < ]

tezlo

30x faster on one check..
its the difference of working with string and numbers

function d0(func, n)
	n = n or 100
	local s = clock()
	for i = 1, n do func() end
	local e = clock()
	return e - s
end

function this()
end

function that()
end

function Main()
	SendToNick("tezlo", "*** "..d0(this, 5000))
	SendToNick("tezlo", "*** "..d0(that, 5000))
end

BlazeXxX

Thank You Tezlo and Klownietklowniet ! It works like a charm.. I couldn't reply till now, because my IP Range is being blocked from the forum it seems for no reason :S

Byeez,
BlazeX

nEgativE

#30
QuoteOriginally posted by DarkElf
Try this...

<?php
-- Date: 09-06-2003
--
--
code from klownietklowniet
-- network: [ > DC - UniteD < ]
--
--
Request by Skippy
--
--
Block ip ranges. Key in table is the start of the range and the value is the end

BotName
= "ipRangeR"


blockedips=

{

--
start(key) = end of range(value)

[
"62.36.0.0"] = "62.36.204.103"
}

function
Main()
frmHub:RegBot(BotName)
end

function NewUserConnected(curUser)
if
BlockedIp(curUser.sIP) == 1 then
curUser
:SendPM(BotName, "Your ip belongs to an ip range that is not allowed into this hubs!")
curUser:SendPM(BotName, "You are beeing disconnected!")
SendPmToOps(BotName, "User "..curUser.sName.." with ip "..curUser.sIP.." was disconnected by "..BotName.."!")
curUser:Ban()
end

end

------------------------------------------------------------------------------------
--
// This function checks to see if users ip should be blocked from entering the hub
------------------------------------------------------------------------------------

function
BlockedIp(tmpip)
local r1,g1,a1,b1,c1,d1 = strfind(tmpip, "(%d*).(%d*).(%d*).(%d*)")
for
s,e in blockedips do
local r2,g2,a2,b2,c2,d2 = strfind(s, "(%d*).(%d*).(%d*).(%d*)")
local r3,g3,a3,b3,c3,d3 = strfind(e, "(%d*).(%d*).(%d*).(%d*)")
if
a1 > a2 and a1 < a3 then
return 1
elseif a1==a2 and a1==a3 then
if b1 > b2 and b1 < b3 then
return 1
elseif b1==b2 and b1==b3 then
if c1 > c2 and c2 < c3 then
return 1
elseif c1==c2 and c1==c3 then
if d1 > d2 and d1 < d3 then
return 1
else
return
0
end
elseif c1==c2 then
if d1 >d2 then
return 1
else
return
0
end
elseif c1==c3 then
if d1 <d3 then
return 1
else
return
0
end
else
return
0
end
elseif b1==b2 then
if c1>c2 then
return 1
elseif c1==c2 then
if d1 > d2 then
return 1
else
return
0
end
else
return
0
end
elseif b1==b3 then
if c1<c3 then
return 1
elseif c1==c3 then
if d1<d3 then
return 1
else
return
0
end
else
return
0
end
else
return
0
end
elseif a1==a2 then
if b1>b2 then
return 1
elseif b1==b2 then
if c1>c2 then
return 1
elseif c1==c2 then
if d1>c2 then
return 1
else
return
0
end
else
return
0
end
else
return
0
end
elseif a1==a3 then
if b1<b3 then
return 1
elseif b1==b3 then
if c1<c3 then
return 1
elseif c1==c3 then
if d1<d3 then
return 1
else
return
0
end
else
return
0
end
else
return
0
end
else
return
0
end
end
end

<?


Hi there, nice script, how do i can add more IPs ?
tried: ["200.148.0.0", "200.169.0.0"] = "200.148.255.255", "200.169.255.255"

got this: Syntax error: `]' expected;
  last token read: `,' at line 36 in file `F:\servidor\p2p\ptokax\ipranger.lua'

Hehe.. also tried: ["201.7.0.0"] = "201.7.255.255", ["200.100.141.0"] = "200.100.144.255"

But i think that 2? does not work, had some user in.

Please ? :(

SMF spam blocked by CleanTalk