IP Bot
 

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 Bot

Started by TheSig, 15 December, 2003, 14:14:11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TheSig

Realy Worked script.
file "data/local.net" contains allowed networks data like this (one record per line):
  10.10.10.10/24
-- ********************************************
-- * IPBot (allowed IP checking script) v0.1  *
-- * (c) 2003 by TheSig   *
-- ********************************************
Bot = "IPBot" 
IPList = "data/local.net" 
oAllow={} 
oMasks={} 
sbns=0 

function LongToBin(L)
  if (L == 0) then
    b = "0"
  else
    b = ""
    tl = L
    for i=1,32 do
      r0 = mod(tl,2) 
      if (r0 == 0) then
        b = "0"..b
        tl = tl / 2
      else
        b = "1"..b
        tl = (tl - r0) / 2
      end
    end
  end
  return b
end

function GetHex(L) 
  if tonumber(L,10) <= 15 then 
    a = "0"..format("%x",L) 
  else 
    a = format("%x",L) 
  end 
  return a  
end 

function GetIPLong(IP) 
  r,g,a,b,c,d = strfind(IP, "(%d*).(%d*).(%d*).(%d*)") 
  a1= GetHex(a) 
  b1= GetHex(b) 
  c1= GetHex(c) 
  d1= GetHex(d) 
  s = a1..b1..c1..d1 
  e = tonumber(s, 16) 
  return e 
end 

function GetIPSubnet(IP) 
  r,g,a,b,c,d,m = strfind(IP, "(%d*).(%d*).(%d*).(%d*)/(%d*)") 
  ipl = GetIPLong(a.."."..b.."."..c.."."..d) 
  m = tonumber(m,10) 
  return ipl,m 
end 

function LoadSubnets() 
  sbns=0 
  readfrom(IPList) 
  repeat 
    s = read("*l") 
    if (s) then 
      if (strsub(s,1,1) ~= "#") then 
        sbns=sbns+1 
        oAllow[sbns],oMasks[sbns]=GetIPSubnet(s) 
      end 
    end 
  until (s == nil) 
  readfrom() 
end 

function TestInSubnet(UserIP,SubnetIP,MaskLen)
  UIP = strsub(LongToBin(UserIP),1,MaskLen)
  SIP = strsub(LongToBin(SubnetIP),1,MaskLen)
  if (UIP == SIP) then
    sny = 1
  else
    sny = 0
  end
  return sny
end

function TestIP(TestIP)
  allowip = 0
  for i=1,sbns do
    if (TestInSubnet(GetIPLong(TestIP),oAllow[i],oMasks[i]) == 1) then
      allowip = 1
    end
  end
  return allowip
end

function Main() 
  frmHub:RegBot(Bot) 
  LoadSubnets()
end 

function NewUserConnected(curUser) 
  theIP=curUser.sIP 
  if (TestIP(theIP) ~= 1) then 
    curUser:SendPM(Bot,"Your IP isn't from [LV]zone .... If it is not correct please contact admin thesig@fastpage.org") 
    curUser:SendData("$ForceMove signest.fastpage.org:4112|") 
  end 
end


c h i l l a

thats a cool script.. but I think the Compute Fuktion is  faster than yours, when it comes to many connection at a time.

IceCoder


SMF spam blocked by CleanTalk