PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Requiem on 29 December, 2004, 23:59:00

Title: IP Range blocker / allower
Post by: Requiem on 29 December, 2004, 23:59:00
I urgently need a tiny script to allow only IPs between 160.75.0.0 and 160.75.255.255.

Thank you for your interest.

P.S. I tried to use NightLitch's IP-Shield, but couldn't use it. Maybe someone can teach me how to use it instead of writing a new script.
Title:
Post by: blackwings on 30 December, 2004, 00:51:22
Use this script =
http://www.plop.nl/ptokaxbots/Phatty/RB_v2.05.rar

at line 58 in the script, change this line =
if Blocked(user.sIP) == 1 thenTo this line =
if Blocked(user.sIP) ~= 1 then
Then edit the Ranges.dat (in the RangeBlaster folder)  with notpad, delete all the ranges and add this (then save it) =
160.75.0.0|160.75.255.255

With this script and these changes, you will get what you wanted - A script that only allowed users from this IP-Range = 160.75.0.0-160.75.255.255, to connect to the hub.

enjoy
Title:
Post by: Requiem on 30 December, 2004, 01:15:28
thank you. will try it. may I request sth too? May these blocked IPs redirected to another hub ?
Title:
Post by: DJ Bert on 30 December, 2004, 01:18:33
Tested that script. It works fine :D

Grtzzz
DJ Bert
Title:
Post by: Requiem on 30 December, 2004, 01:27:35
That script didin't work the way blackwings told and I found my way. I have only these two entries in my Ranges.dat
0.0.0.0|160.74.255.255
160.76.0.0|255.255.255.255
. Now it works really nice. Do I have any chance to redirect disconnected users?
Title:
Post by: blackwings on 30 December, 2004, 01:36:33
QuoteOriginally posted by Requiem
That script didin't work the way blackwings told and I found my way. I have only these two entries in my Ranges.dat
0.0.0.0|160.74.255.255
160.76.0.0|255.255.255.255
. Now it works really nice. Do I have any chance to redirect disconnected users?
ok, have this instead in the .dat file =
127.0.0.1|127.0.0.3
160.75.0.0|160.75.255.255

I think that you meant when it didn't work, was that you couldn't connect. And that is probably because the script saw your network card IP or your internal IP if you have a local network (192.168.*.*). I have  as you see above, added the network card IP. If it still doesn't work, check ptokax for what IP it see you as (if it isn't the network card IP, then it's the internal IP).

With those you added, you will allow the whole internet to connect.
Title: no its not that
Post by: Requiem on 30 December, 2004, 01:52:44
any of users in our network wasnt able to access the hub, the problem is not that but i am ok now. Can we redirect disconnected users?
Title:
Post by: Pothead on 30 December, 2004, 02:20:59
probably. try changing
user:Disconnect()
to
Redirectaddy = frmHub:GetRedirectAddress()
user:SendData("$ForceMove "..Redirectaddy)

the first line gets the redirect addy from the hub, and might wanna go near the top of the script ;)

edited to remove smilies from code :S
Title: SUCCESS :))
Post by: Requiem on 30 December, 2004, 02:40:58
finally did it. thank you a lot.

--//RangeBlaster v2.07 by Phatty
--//IP Keys written by John, and Phatty
--//Edited by Requiem with ideas from Pothead

Bot = "BotName"
sRedirect = frmHub:GetRedirectAddress()

Ranges = {}

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

function LoadIps()
local tmp = 0
local handle = openfile("RangeBlaster/Ranges.dat","r")
line = read(handle)
while line do
tmp = tmp + 1
local s,e,ipr1,ipr2 = strfind(line,"(%S+)|(%S+)")
if ipr2 == nil then
SendToAll(Bot,"Error on line "..line)
end
local s,e,ipa1,ipb1,ipc1,ipd1 = strfind(ipr1, "(%d*).(%d*).(%d*).(%d*)")
local s,e,ipa2,ipb2,ipc2,ipd2 = strfind(ipr2, "(%d*).(%d*).(%d*).(%d*)")
si1 = CheckNumber(ipa1)..CheckNumber(ipb1)..CheckNumber(ipc1)..CheckNumber(ipd1)
si2 = CheckNumber(ipa2)..CheckNumber(ipb2)..CheckNumber(ipc2)..CheckNumber(ipd2)
Ranges[si1] = si2
line = read(handle)
end
SendToAll(Bot,"Successfully loaded "..tmp)
end

function Blocked(userip)
local s,e,range1,range2,range3,range4 = strfind(userip,"(%d+).(%d+).(%d+).(%d+)")
checker = CheckNumber(range1)..CheckNumber(range2)..CheckNumber(range3)..CheckNumber(range4)

--SendToAll(Bot,"IP-Test..."..checker)

for i,p in Ranges do
local s,e,xstart = strfind(i, "(%d*)")
local s,e,xend = strfind(p, "(%d*)")

if checker > xstart and checker < xend then
collectgarbage()
flush()
return 1
else
end
end
end

function CheckNumber(number)
numbera = tonumber(number)
if numbera < 10 then
numbera = "00"..number
elseif numbera < 100 then
numbera = "0"..number
else
numbera = number
end
return numbera
end

function DataArrival(user,data)
if strsub(data, 1, 13) == "$ValidateNick" then
if Blocked(user.sIP) == 1 then
user:SendData(Bot, "This hub is private, you will now be redirected!")
user:SendData(Bot, "Disconnected... Waiting for redirection... ")
user:SendData("$ForceMove "..sRedirect)
SendPmToOps(Bot, user.sName.." - "..user.sIP.." has been blasted by "..Bot.."!")
end
end
end

EDIT: As a guide to users that doesn't know hot to edit it, adding Ranges.dat 's content for allowing only 160.75.0.0-160.75.255.255 range for example.

0.0.0.0|160.74.255.255
160.76.0.0|255.255.255.255
Title:
Post by: blackwings on 30 December, 2004, 02:47:22
I see now why the script didn't work for you, you didn't make the first change I asked you about, which is to change this =
if Blocked(user.sIP) == 1 then
To this =
if Blocked(user.sIP) ~= 1 then
Do you see the difference :P

EDIT: in this script, at line 58, these 2 things has 2 different menings =
"==" - means that it will block everyone that has a IP in those IP-Ranges in the .dat file.
"~=" - means that it will allow IP's from the IP-Ranges in the .dat file, but block everyone else.

"~=" is faster for you. It is also easier if you want to have more ip-ranges to enter your privat hub
Title:
Post by: blackwings on 30 December, 2004, 02:51:35
QuoteOriginally posted by Requiem
EDIT: As a guide to users that doesn't know hot to edit it, adding Ranges.dat 's content for allowing only 160.75.0.0-160.75.255.255 range for example.

0.0.0.0|160.74.255.255
160.76.0.0|255.255.255.255

Wrong, do the change I said in the post before and then you can use the IP-Range I first gave you.