ip blocker with table
 

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 blocker with table

Started by -RICK-, 10 April, 2005, 18:30:18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

-RICK-

-- IP block lua 5
-- created by  -RICK- and Amsterdambulldogs
-- make a ipblocker.tbl in your script folder
----------------------------------------------------------------------------

sBot ="IPblocker" --frmHub:GetHubBotName() 
File = "ipblocker.tbl"
ipallowed = {}

-- 1=on / 0=off                -- who can add a ip
SendTo = {
[0] = 1,   -- Masters
[1] = 1,   -- Operators
[2] = 0,   -- Vips
[3] = 0,   -- Regs
[4] = 1,   -- Moderator
[5] = 1,   -- NetFounder     
[-1] = 0,  -- Users
}

function Main()
	dofile(File)
end

function UserIPArrival(user, data)
if (IspChecker(user.sIP) == 0) then 
SendToOps(sBot, "found a user with a wrong ip and removed him/her.")
user:SendData(sBot, "Your IP is NOT allowed in this hub.")  
user:Ban()
end 
end 

function IspChecker(IP) 
local accept = 1 

local s,e,ip1,ip2,ip3,ip4 = string.find(IP, "(%d+)%.(%d+)%.(%d+)%.(%d+)") 
local userIP = Addzero(ip1)..Addzero(ip2)..Addzero(ip3)..Addzero(ip4) 
userIP = (userIP) 

for i=1, table.getn(ipallowed) do 
local s,e,a1,a2,a3,a4 =  string.find(ipallowed[i], "(%d+)%.(%d+)%.(%d+)%.(%d+)") 
local aIP = Addzero(a1)..Addzero(a2)..Addzero(a3)..Addzero(a4) 
aIP = (aIP) 


if (userIP == aIP) then
accept = 0 
break 
end 
end 
return accept 
end 



function Addzero(number) 
iAux = tonumber(number) 
if (iAux < 10) then 
number = "00"..number 
elseif (iAux < 100) then 
number = "0"..number 
else 
number = number 
end 
return number 
end 

function ChatArrival(user, data)
local data = string.sub(data,1,-2)
	if (string.sub(data,1,1) == "<" or string.sub(data,1,5+string.len(sBot)) == "$To: "..sBot) then
		s,e,cmd = string.find(data, "%b<>%s+(%S+)")
		if cmd == "!addiptolist" then
			if SendTo[user.iProfile] == 1 then
				s,e,ip = string.find(data, "%b<>%s+%S+%s(.*)")
					if ip == nil then
						local dsp0
						dsp0 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-<>=-=\r\n"
						dsp0 = dsp0.."\t u didn't fill in a ip\r\n"
						dsp0 = dsp0.."\t=-=<>=-=-=-=-=-=-=-=<>=-=\r\n"
						user:SendData(sBot,dsp0)
						return 1
					else
						table.insert(ipallowed, ip)
						SaveToFile(File , ipallowed , "ipallowed")
						dsp0 = "\t Done: "..ip.." added to ban list"
						user:SendData(sBot,dsp0)
						dsp0 = nil
						return 1
					end
			end
		end
	end		
end

function Serialize(tTable, sTableName, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");
	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");
	sTab = sTab or "";
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in tTable do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
		if(type(value) == "table") then
			Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end
		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end

function SaveToFile(file , table , tablename)
	local ipfile = io.open(file, "w+")
	ipfile:write(Serialize(table, tablename))
	ipfile:close()
end

___________________________

ipblocker.tbl  (in your scripts folder)

-------------------------------------------

ipallowed = {
}

------------------------------------------------

jiten

Hum, u posted in the wrong Section. It should be Lua 5 Finished Scripts.

Btw, try using the [ CODE] [ /CODE] thingy (without the spaces between the "[", "C" and "/".

Best regards.

SMF spam blocked by CleanTalk