PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: IceCoder on 15 December, 2003, 16:37:33

Title: IP Checker By IceCoder
Post by: IceCoder on 15 December, 2003, 16:37:33
To use this write ranges like:
213.112.0.0-213.115.255.255;BBB


-- By IceCoder
-- Checks IP ranges

sBot = "-?-IPGuard-?-"
sRejectMessage = "Sorry, connections from your IP number is not allowed here. This hub is for 10Mbit users only. You are beeing redirected."

Allowip = {}
IpFile = "ip/ipranges.txt"

function Main()
frmHub:RegBot(sBot)
LoadIpList()
end


function NewUserConnected(curUser)
   allowed = CheckIP(curUser.sIP)
   if allowed == 0 then
    curUser:SendData(sBot, sRejectMessage)
    curUser:SendData("$ForceMove "..frmHub:GetRedirectAddress())
   end
end

function CheckIP(sIP)
local s,e,s1,s2,e1,e2, ipa, ipb
ipa,ipb = ComputeIP(sIP)
 for range,ab in Allowip do
  _,_,s,e = strfind(range, "(%S+)-(%S+)")
  s1,e1 = ComputeIP(s)
  s2,e2 = ComputeIP(e)
  if (tonumber(s1) <= tonumber(ipa)) and (tonumber(ipa) <= tonumber(s2)) then
   SendToAll(sBot, "1 Right")
   SendToAll(sBot, e1.." <= "..ipb.."     "..ipb.." <= "..e2)
   if (tonumber(e1) <= tonumber(ipb)) and (tonumber(ipb) <= tonumber(e2)) then
    SendToAll(sBot, "2 Right")
    return 1
   end
  end
 end
 return 0
end

function ComputeIP(sIP)
 local a,b
  _,_,a,b = strfind(sIP, "(%d+.%d+).(%d+.%d+)")
 return a, b
end

function LoadIpList()
   readfrom(IpFile)
   while 1 do
      local line = read()
      if line == nil then
         break
      else
               range = strsub(line, 1, strfind(line, ";")-1)
                         isp = strsub(line, strfind(line, ";")+1,-1)
          Allowip[range] = isp
      end
   end
   readfrom()
end
Title:
Post by: c h i l l a on 15 December, 2003, 16:53:29
Little commercial ;),

depending on how many IP-Ranges you have.. above 10
the Logger is the fastest.

other question does your compute function really work?
Title:
Post by: plop on 15 December, 2003, 17:53:34
. matches everything, you need 2 escape it  %.

plop
Title:
Post by: IceCoder on 15 December, 2003, 18:45:17
it works but it is a syntax
Title:
Post by: tezlo on 15 December, 2003, 20:19:59
until you get logger to precompute ranges.. calling it "the fastest" is not really accurate

anyway this doesnt work
Title:
Post by: c h i l l a on 15 December, 2003, 20:41:08
nope tezlo its really faster, cause it, searches the IP's  by 2^x search...

so like it only needs 10 runs do check if the IP is in 1024 IP-Ranges,  beat that with a foreach function...

thats why the Logger is the fastest, IP-Range script around..  precomputing the IP's  wouldn't make much difference, anymore.
Title: Hi c h i l l a!!
Post by: WickeD on 15 December, 2003, 21:03:11
You are the best c h i l l a !!!!

Good work whit all scripts...!!

Thx m8!    ;)

//WickeD
Title:
Post by: IceCoder on 15 December, 2003, 22:40:51
the scripts works but if you write wrong in the txt file it gonna be a syntax


/ lol @ my english
Title:
Post by: c h i l l a on 15 December, 2003, 23:09:39
thanks wicked,  but wouldn't go so far me the best.. haha, but thanks anyway, first I thaught you were opium because of the little devil ;)..

IceCoder,

I checked you script a little and I haven't tested it but you compute func, is quite cool actually, I think it really works, but I think it will only work like this but dunno, haven't tested, yet..


curUser.sIP
ipa,ipb = ComputeIP(curUser.sIP)


for range,ab in Allowip do
_,_,s,e = strfind(range, "(%S+)-(%S+)")
s1,e1 = ComputeIP(s)
s2,e2 = ComputeIP(e)
if tonumber(s1)<= ipa and ipa <= tonumber(s2) and tonumber(e1)<=ipb and ipb<=tonumber(e2) then
end
end

function ComputeIP(sIP)
local a,b
_,_,a,b = strfind(sIP, "(%d+.%d+).(%d+.%d+)")
return a, b
end

but anyway  the logger is faster ;)

but I prefer the compute func from patcezk, which is slightly better to understand and surely works

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
Title:
Post by: IceCoder on 16 December, 2003, 10:29:51
Thanks anyway  :D


it works but you have to write right ranges in the txt file if you write wrong it gonna be a syntax
Title:
Post by: IceCoder on 16 December, 2003, 14:05:02
Do you know why no one has posted a IP/ISP Script in this forum?  ?(
Title:
Post by: tezlo on 16 December, 2003, 16:18:22
right.. last post on this subject

its not just how many runs..
but also what you need to do in each of them
and precomputing the ranges does make huge difference

i just tested with a table of 200 ranges and..
your raw tSearch performs the same as a plain search on precomputed values

the more ranges the better tSearch performs relatively
and obviously.. tSearch will perform best on a sorted table

edit.. actually logger is the fastest only when you have over 200 ranges

sorry to spoil your illusion but you dont want to lie to these fine people
Title:
Post by: c h i l l a on 16 December, 2003, 18:47:38
nope never lie to them..  but you should maybe post the script you used..  or so..
no proof, and we can go on and on and on...

but I cam up with 10 cause then the logger needs,
3 searches for a 10 items big table + 3*2 computings
equals 9 funcs  thats less than 10.

well I tested it again the tsearch func..  and let it compute a ip 2 twice with each search...  just like the logger does...  and results are you can't test it unless you have a real time OS.  You got one, then I apologize...

but form the average runs I did...  I had some weird results...  normal search is about the same up to 100  search entries,  my cpu time was always zero.. then on any type of search...  above then..  it switches between zero and xE-5  and above 1000 entries then I see a  difference between  the searchalgo.  and a normal search, well as said 100 times before the kernel fucks it up.

ends up to really start a battle we need a real time OS.
Title:
Post by: IceCoder on 16 December, 2003, 19:25:10
hehe tezlo post your script here so we can see  :D
Title:
Post by: IceCoder on 17 December, 2003, 15:11:18
did you guys live me??  :O
Title:
Post by: IceCoder on 18 December, 2003, 13:59:57
Can someone post more  IP checks here?  :O
Title:
Post by: meumeu on 23 December, 2003, 19:04:47
thx a lot thats the script i m looking for.
i have problem about sending mesages to main chat.
how can i disable it??
i mean how can i disabe for examle:
1 Right
0.0 <= 82.208 82.208 <= 255.255
2 Right
Title:
Post by: IceCoder on 23 December, 2003, 19:59:45
-- By IceCoder
-- Checks IP ranges

sBot = "-?-IPGuard-?-"
sRejectMessage = "Sorry, connections from your IP number is not allowed here. This hub is for 10Mbit users only. You are beeing redirected."

Allowip = {}
IpFile = "ip/ipranges.txt"

function Main()
frmHub:RegBot(sBot)
LoadIpList()
end


function NewUserConnected(curUser)
allowed = CheckIP(curUser.sIP)
if allowed == 0 then
curUser:SendData(sBot, sRejectMessage)
curUser:SendData("$ForceMove "..frmHub:GetRedirectAddress())
end
end

function CheckIP(sIP)
local s,e,s1,s2,e1,e2, ipa, ipb
ipa,ipb = ComputeIP(sIP)
for range,ab in Allowip do
_,_,s,e = strfind(range, "(%S+)-(%S+)")
s1,e1 = ComputeIP(s)
s2,e2 = ComputeIP(e)
if (tonumber(s1) <= tonumber(ipa)) and (tonumber(ipa) <= tonumber(s2)) then
if (tonumber(e1) <= tonumber(ipb)) and (tonumber(ipb) <= tonumber(e2)) then
return 1
end
end
end
return 0
end

function ComputeIP(sIP)
local a,b
_,_,a,b = strfind(sIP, "(%d+.%d+).(%d+.%d+)")
return a, b
end

function LoadIpList()
readfrom(IpFile)
while 1 do
local line = read()
if line == nil then
break
else
range = strsub(line, 1, strfind(line, ";")-1)
isp = strsub(line, strfind(line, ";")+1,-1)
Allowip[range] = isp
end
end
readfrom()
end


----------------------------------------
Thx meumeu :P

This is without:
1 Right
0.0 <= 82.208 82.208 <= 255.255
2 Right
Title:
Post by: meumeu on 24 December, 2003, 01:37:14
Thats the bot everyone must use i use 10 ranges and no problem it ll grow up later.  :D
Title:
Post by: IceCoder on 24 December, 2003, 16:51:18
hehe  :D
Title:
Post by: acethecase on 07 January, 2004, 15:35:50
Hi..
Can some one please post IP Range for/ISP [BBB]
I only want to have 10Mbit in my hub..

TY ppl ..
Title:
Post by: sajy2k on 07 January, 2004, 18:30:11
hello, i need  a script which can automatically  detect and ban the users who use fake IP . Please anyone post the scripts
Title:
Post by: NightLitch on 07 January, 2004, 18:39:19
suggest you try this one:

--Correct-IP-V.1 for Active users
--Idea by [aDe] , by c h i l l e r
--For TD4

function Main()
frmHub:EnableSearchData(1)
end

function DataArrival(curUser, data)
if (strsub(data, 1, 7) == "$Search") then
_,_,userIP_Port,_ = strfind( data, "$Search%s+(%S+)%s+(.*)" )
_,_,userIP,_ = strfind( userIP_Port, "(%S+):(.*)" )
IsIPnumber = gsub(userIP,"%p", "")
IsIPnumber = tonumber(IsIPnumber)
if IsIPnumber then
if userIP ~= curUser.sIP then
curUser:SendData("Please insert your correct Active IP address : "..curUser.sIP)
curUser:Disconnect()
end
end
end
end
Title:
Post by: Intel on 08 January, 2004, 18:46:06
How is it possible to have a Fake ip ? I mean Is it really possible to fake the ip ?
Title: IP ranges
Post by: [G-T-E]Gate? on 16 January, 2004, 01:00:14
Ive just obtained a new isp contract with 10mb. I wish to allow only 10mb and or over to enter hub.
Ive been looking for ip ranges to add to the text file but have had no luck. Can anyone please assit me.
I just copied the -- By IceCoder
-- Checks IP ranges
Title:
Post by: Icanos on 18 June, 2004, 22:08:22
omg, IceCoder  :D , whats that for script?  ;)