PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: phalon on 11 November, 2003, 19:43:36

Title: IP Filter
Post by: phalon on 11 November, 2003, 19:43:36
Hi, first of all I would like to thank you for a great board.

I have some problems making my own bot!
As I have been trying to make an ip filter bot.

I need to be able to allow ip addresses (range)
For instance I would like to allow

192.168.101.100 to 192.168.101.199 and
192.168.202.70 to 192.168.205.200

But all other ip would be blocked.

I have been searching for a script like this in this board
But to no avail, if there is one however I apologize

Kind regards
phalon





Title:
Post by: SaintSinner on 11 November, 2003, 19:59:34
QuoteOriginally posted by phalon
Hi, first of all I would like to thank you for a great board.

I have some problems making my own bot!
As I have been trying to make an ip filter bot.

I need to be able to allow ip addresses (range)
For instance I would like to allow

192.168.101.100 to 192.168.101.199 and
192.168.202.70 to 192.168.205.200

But all other ip would be blocked.

I have been searching for a script like this in this board
But to no avail, if there is one however I apologize

Kind regards
phalon


these ip ranges are for your internal home/office network, if you only allow these..the 192.x.x.x ip ranges and block everyone else,...then you just blocked the whole internet.
are you perhaps on a school lan?
Title:
Post by: NightLitch on 11 November, 2003, 20:00:05
Here you go look at this...

This should be all you need...  :))

LOGGER by C h i l l a

Click Here... (http://board.univ-angers.fr/thread.php?threadid=116&boardid=12&styleid=1&sid=579bd8b13817711a69f077accfb1883c)

/NightLitch
Title:
Post by: phalon on 11 November, 2003, 20:54:55
Thank you for your reply SaintSinner. To answer your question then 192.xxx.xxx.xxx is a "dummy" ip, what i mean is that I could put some ip?s like for instance ip ranges of one isp but not another.

Thank you NightLitch I will take alook at LOGGER

Kind regards
phalon
Title:
Post by: tezlo on 12 November, 2003, 11:40:28
there is also a smaller and faster alternative (http://board.univ-angers.fr/thread.php?threadid=281&boardid=11&sid=b296be61a1f1562a277faa709d6c7b2c) ;)
Title: Great tezlo
Post by: phalon on 18 November, 2003, 21:33:20
Thank you tezlo, this is what i was looking for
Title: I am having some problems!
Post by: phalon on 22 November, 2003, 18:05:24
I want to allow these ip number ranges but exclude all others.

[Og Vodafone]
217.9.128.0 - 217.9.143.255
213.176.128.0 - 213.176.159.255
213.213.128.0 - 213.213.159.255
194.144.0.0 - 194.144.255.255
193.4.0.0 - 193.4.255.255

The problem, i am facing is


There is a user with the ip 194.144.12.128 he can not enter until i change the range 194.144.0.0 - 194.144.255.255 to 194.144.12.0 - 194.144.12.255
it seems that the script only reads the last line of the ip.

Am I missing something or just a little dumb :-), can you please help me?


this is the script

---start---

ipRanges = {}

denyMsg = " You do not belong here! (sendu p?st ? spassi@simnet.is ef ?? ert ?samm?la)"

function compute(ip)
   local s, e, a, b, c, d = strfind(ip, "^(%d+).(%d+).(%d+).(%d+)$")
   if s then return a*16777216 + b*65536 + c*256 + d end return 0
end

function checkrange(table, ip)
   return foreachi(table, function(id, tmp)
      if (%ip >= tmp[1]) and (%ip <= tmp[2]) then return tmp end
   end)
end

function load(name, data)
   ipRanges[name] = ipRanges[name] or {}
   gsub(data, "(%S+) %- (%S+)", function(s, e)
      s, e = compute(s), compute(e)
      tinsert(ipRanges[%name], { s, e })
   end)
end

function Main()
   local f = openfile("ranger.dat", "r") assert(f, "ranger.dat")
   local file = read(f, "*a") closefile(f)   gsub(file, "%[(%S+)%]([%c%d%s%-%.]+)", load)
end

function NewUserConnected(user)
   local ip, isp = compute(user.sIP)
   for name, range in ipRanges do
      if checkrange(range, ip) then return end
   end user:SendData(denyMsg) user:Disconnect()
end

---end---

And this is the content of ranger.dat

---start---

[LOCALHOST]
127.0.0.1 - 127.0.0.255

[LAN]
192.168.0.0 - 192.168.0.255
192.168.1.0 - 192.168.1.255
192.168.2.0 - 192.168.2.255


[Hringi?an ehf]
213.190.96.0 - 213.190.127.255


[?slensk erf?agreining hf]
212.126.224.0 - 212.126.255.255

[Og Vodafone]
217.9.128.0 - 217.9.143.255
213.176.128.0 - 213.176.159.255
213.213.128.0 - 213.213.159.255
194.144.0.0 - 194.144.255.255
193.4.0.0 - 193.4.255.255

[Landss?mi ?slands hf]
157.157.0.0 - 157.157.255.255
192.147.34.0 - 192.147.34.255
194.105.224.0 - 194.105.255.255
212.30.192.0 - 212.30.223.255
213.167.128.0 - 213.167.159.255

[L?naNet]
213.220.64.0 - 213.220.120.0
62.145.128.0 - 62.145.159.255
81.15.0.0 - 81.15.127.255

[Fj?ltengi]
213.220.120.0 - 213.220.127.255

[Margmi?lun Internet ehf]
217.151.160.0 - 217.151.191.255



[Ranns?kna- og H?sk?lanet ?slands]
130.208.0.0 - 130.208.255.255

[Skyggnir hf]
217.28.176.0 - 217.28.180.255

[Sk?rr hf]
82.148.64.0 - 82.148.75.0
82.148.75.0 - 82.148.95.255

[Snerpa ehf]
193.109.16.0 - 193.109.31.255

---end---