PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Vaderv on 27 October, 2003, 14:47:18

Title: Allow only specified ip-range
Post by: Vaderv on 27 October, 2003, 14:47:18
Hi all!

Im looking for a script that ONLY allows specified ip-ranges to access the hub, and all others to be disconnected from the hub.

I only want to allow ip-addresses from a number of specified ISP:s to enter my hub.

I have looked around to find some but i have only found scripts that blocks specified ip-ranges.

Thanks in advance.
Title:
Post by: tezlo on 27 October, 2003, 15:00:12
here.. again
-- easyranger
-- tezlo

ipRanges = {}

denyMsg = " You dont belong here."

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
youll need ranger.dat in this form..

[LAN]
192.168.0.0 - 192.168.0.255
192.168.2.0 - 192.168.2.255

[LOCAL]
127.0.0.1 - 127.0.0.255
...
Title:
Post by: Vaderv on 27 October, 2003, 15:26:37
a question, will this work:

192.168.0.0 - 192.168.5.255

or do i have to write every subnet?
Title:
Post by: tezlo on 27 October, 2003, 16:21:10
any valid range will work :)
Title:
Post by: Vaderv on 27 October, 2003, 16:42:45
Works great!

Thx for the script!
Title:
Post by: blackwings on 17 June, 2004, 21:28:38
Should it be like this in the .dat file??

192.168.2.0 - 192.168.2.255
127.0.0.1 - 127.0.0.255
Title: Ip ranges
Post by: [NL]Portal on 06 August, 2004, 10:56:02
Are there more IP ranges , Ip ranges from fast T1,T2,T3 connections.?

Lets here about it.