PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: nErBoS on 21 April, 2004, 14:50:33

Title: ISP-Checker
Post by: nErBoS on 21 April, 2004, 14:50:33
Hi,

This is the same ISP-Checker that i have in Brain-Master, hope it helps...

--Made by nErBoS

sBot = "IP-Checker"

ipallowed = {      
      "127.0.0.0-127.255.255.255"      
} --eg of how to put isps in this table

function NewUserConnected(user, data)
   if (IspChecker(user.sIP) == 0) then
      user:SendData(sBot, "Your IP is not allowed in this HUB.")
      user:Disconnect()
   end
end

OpConnected = NewUserConnected

function IspChecker(IP)
   local accept = 0

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

   for i=1, getn(ipallowed) do
      local s,e,a1,a2,a3,a4,b1,b2,b3,b4 = strfind(ipallowed[i], "(%d+)%.(%d+)%.(%d+)%.(%d+)-(%d+)%.(%d+)%.(%d+)%.(%d+)")
      local aIP = Addzero(a1)..Addzero(a2)..Addzero(a3)..Addzero(a4)
      aIP = tonumber(aIP)
      local bIP = Addzero(b1)..Addzero(b2)..Addzero(b3)..Addzero(b4)
      bIP = tonumber(bIP)

      if (userIP >= aIP and userIP <= bIP) then
         accept = 1
         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

Best regards, nErBoS
Title:
Post by: kp on 21 April, 2004, 16:17:44
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

equals

x = 5
format("%03d",x)

if i got the manual right, or you can translate the IP to a unique number and compare that, or do it like in GeoIP script, too many ways all lead to rome i guess you should be fine.
Title:
Post by: nErBoS on 22 April, 2004, 14:50:05
Hi,

Both ways work :)

Best regards, nErBoS
Title:
Post by: kp on 22 April, 2004, 14:54:10
yes i know, it was just a suggestion
Title:
Post by: nErBoS on 22 April, 2004, 14:59:46
Hi,

I know kp, always welcomed, i didn?t got offended :)
But i perfer this way :P

Best regards, nErBoS
Title:
Post by: kp on 22 April, 2004, 16:46:17
sure np, mostly people like it when they can reduce many lines to one line, cause it mostly implements a faster handling, not always but mostly,

also check this

func(strnum)
for _ = (strlen(strnum)+1),3 do
strnum = "0"..strnum
end
return strnum
end

is the board only slow to me?