IP Range Blocker
 

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

IP Range Blocker

Started by BlazeXxX, 31 October, 2003, 02:58:14

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BlazeXxX

As Lot of people using TD4 Versions, Here is the useful script written by KlownietKlowniet


-- Copy From this line

-- 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
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
return 1

elseif c1==c3 then

if d1
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
return 1

elseif b1==b3 then

if c1
return 1

elseif c1==c3 then

if d1
return 1

else

return 0

end

else

return 0

end

else

return 0

end

else

return 0

end

end

end

-- Finish copying

xfiles

Hi Blazexxx,

how do i include more IP Ranges in that script
i tryed to write the ip ranges one below the other
["200.223.0.0"] = "200.223.255.255"
["200.148.0.0"] = "200.148.0.0"

but i allways get this syntax

Syntax error: `}' expected (to close `{' at line 5);
  last token read: `[' at line 10 in file `...e Dateien\0.330.b15.25.dbg mit RoboCop v5.0b\scripts\IpRanger 2.lua'

It would be great if you could help me with this one.
thx m8

c h i l l a

#2
when I see all those if's I get a headache,

so better use this one here

i will also release a IP-range blocker, stripped from LIS, witch is certainly the fastest when you have over 1000 ranges, or I haven't seen anything faster till now.

c h i l l a

#3
--IP-Bot from LIS by chill
--built for handling many IP-Ranges
--IP-DenyRanges at   [URL]http://fdw.ath.cx/p.scripts/IP-DenyRanges.zip[/URL]


BIPRange = {}
GIPRange = {}
CompRange = {}

File2 = "IP-DenyRanges.txt"
File3 = "IP-AllowRanges.txt"

dofile(File2)
dofile(File3)

ALLOWDENY = 2   -- 1 = only allows ip's, 2 = denys ip's

function Main()
	if ALLOWDENY == 1 then
		ComputeIPTable(GIPRange)
	elseif ALLOWDENY == 2 then
		ComputeIPTable(BIPRange)
	end
end

function DataArrival(curUser,data)
	if strsub(data,1,13) == "$ValidateNick" then
		CheckIP(curUser)
	end
end


function CheckIP(curUser)
	if (ALLOWDENY == 1) then
		if (tSearch(CompRange,ComputeIP(curUser.sIP)) == "NOTFOUND") then
			curUser:Disconnect()
		end
	elseif (ALLOWDENY == 2) then
		if (tSearch(CompRange,ComputeIP(curUser.sIP) ~= "NOTFOUND") then
			curUser:Disconnect()
		end
	end
end


function ComputeIPTable(table)
	CompRange = {}
	for i = 1,getn(table) do
		tinsert(CompRange,{ComputeIP(table[i][1]),ComputeIP(table[i][2]),table[i][3]})
	end
end

function ComputeIP(curIP)
	local _,_,a,b,c,d = strfind(curIP, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
	if a and b and c and d then
		return a*16777216 + b*65536 + c*256 + d
	end
end

function tSearch(table,sItem,ret)
	local iStart,iEnd,iMid,size = 1,getn(table),floor(getn(table)/2),getn(table)
	while (iStart <= iEnd) do
		if iMid < 1 then
			iMid = 1
		elseif iMid > size then
			iMid = size
		end
		if table[iMid][1] <= sItem and table[iMid][2] >= sItem then
			return table[iMid][3]
		elseif table[iMid][1] > sItem then
			iEnd = iMid - 1
			iMid = iMid - floor((iEnd-iStart)/2) - 1
		elseif table[iMid][1] < sItem then
			iStart = iMid + 1
			iMid = iMid + floor((iEnd-iStart)/2) + 1
		end
	end
	return "NOTFOUND"
end

BlazeXxX

sorry for the late reply xfiles.

e.g. 219.121.58.0 - 219.121.58.255

Thats the format u need to enter.

c h i l l a

#5
--IP-Bot from LIS by chill
--built for handling many IP-Ranges
--RangesFile Format =   IP1-IP2:NETNAME

CompRange = {}

File1 = "IP-Ranges.txt"
Folder = "txt"

ALLOWDENY = 2   -- 1 = only allows ip's, 2 = denys ip's

function Main()
	LoadRanges()
end

function DataArrival(curUser,data)
	if strsub(data,1,13) == "$ValidateNick" then
		CheckIP(curUser)
	end
end

function LoadRanges()
	local handle = openfile(Folder.."/"..File1,"r")
	if handle then
		local line = read(handle)
		while line do
			local _,_,ip1,ip2,name = strfind(line,^(%d+%.%d+%.%d+%.%d+)-(%d+%.%d+%.%d+%.%d+):(.*)$")
			if ip1 then
				tinsert(CompRange,{ComputeIP(ip1),ComputeIP(ip2),name})
			end
			line = read(handle)
		end
		sort(CompRange,function(a,b) return(a[1] < b[1]) end)
		closefile(handle)
	end
end

function CheckIP(curUser)
	if (ALLOWDENY == 1) then
		if (tSearch(CompRange,ComputeIP(curUser.sIP)) == "NOTFOUND") then
			curUser:Disconnect()
		end
	elseif (ALLOWDENY == 2) then
		if (tSearch(CompRange,ComputeIP(curUser.sIP) ~= "NOTFOUND") then
			curUser:Disconnect()
		end
	end
end


function ComputeIPTable(table)
	CompRange = {}
	for i = 1,getn(table) do
 		tinsert(CompRange,{ComputeIP(table[i][1]),ComputeIP(table[i][2]),table[i][3]})
	end
end

function ComputeIP(curIP)
	local _,_,a,b,c,d = strfind(curIP, "(%d+)%.(%d+)%.(%d+)%.(%d+)")
	if a and b and c and d then
		return a*16777216 + b*65536 + c*256 + d
	end
end

function tSearch(table,sItem,ret)
	local iStart,iEnd,iMid,size = 1,getn(table),floor(getn(table)/2),getn(table)
	while (iStart <= iEnd) do
		if iMid < 1 then
			iMid = 1
		elseif iMid > size then
			iMid = size
		end
		if table[iMid][1] <= sItem and table[iMid][2] >= sItem then
			return table[iMid][3]
		elseif table[iMid][1] > sItem then
			iEnd = iMid - 1
			iMid = iMid - floor((iEnd-iStart)/2) - 1
		elseif table[iMid][1] < sItem then
			iStart = iMid + 1
			iMid = iMid + floor((iEnd-iStart)/2) + 1
		end
	end
	return "NOTFOUND"
end				
		
[code]

if you want a message on disconnect

the change this function

[code]
function CheckIP(curUser)
	if (ALLOWDENY == 1) then
		if (tSearch(CompRange,ComputeIP(curUser.sIP)) == "NOTFOUND") then
			curUser:SendData(":P")
			curUser:Disconnect()
		end
	elseif (ALLOWDENY == 2) then
		if (tSearch(CompRange,ComputeIP(curUser.sIP) ~= "NOTFOUND") then
			curUser:SendData(":P")
			curUser:Disconnect()
		end
	end
end

UwV

well chill, very very chill Chilla ..

but ehm, eh ..
the ip list that was used before .. "IP-DenyRanges.txt"  was very nice .. is there a list in this "new" format too?(IP1-IP2:NETNAME)
and if yes where to get it?

and p.s.
  .. please please, Chilla do add some lines to your scripts that explain to us "andigibethics" what are the commands etc. its not always that easy for us readeing them from the script .. ;0)

like the ip-wars .. what is that .. a script just for checking the speed between the three versions that are build in there .. or what else what does it really do?? ... since you rar most thingy's a help.txt would be a nice thing to do for us "absolute beginners"  

don't get me wrong .. i do really like your scripts ..
keep up the good work !!  let the dc-spirit flow .. don't keep us in the dark .. -- write comments in scripts ;0)..
\NL   The knowledge and skills you have achieved are meant to be forgotten so you can float comfortably in emptiness, without obstruction.
" Holly loves me,...  . "      ;o)

& don't forget, the motto is :
  -- SUPPORT YOUR LOCAL DJ'S --

c h i l l a

thx :)

I will add more comments..  it is also better for me as I noticed.

But I got no denyranges for, this current script sorry.

And to the ip.batlle thng, it is just a test, where I tried to compare different ways of denying ip-ranges with a LUA 4.0 standalone.

Well and for me results where as said.
But if you really want to dig into it then I can help you and I will try to explain some things, and how the different ways work.

pHaTTy

yep 2 differ scripts in there chill's and mine, they are both very differ scripts, and comaring to checking 1000 connects, it checks the speed, fortuantly chilla wins, but for 1000 connects in the matter of 4.3 seconds lol, never will happen lol, so im in the safe

or chilla did you make a seperate one?
Resistance is futile!

c h i l l a

nope still that same only added tezlos and another one of mine.

uNiOn

hey people im trying also to find some script that blocks non swedish ip =)
dont relly know how to ad them my self so if anyone can find the time to make the script them self to me finnished with blocked ip range outside sweden i just whant connections like swedish bbb bostream telia adsl chella sunet dont know more swedish connections


!!!cheers m8s!!!

SMF spam blocked by CleanTalk