IP Range blocker / allower
 

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 Range blocker / allower

Started by Requiem, 29 December, 2004, 23:59:00

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Requiem

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.

blackwings

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 then
To 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


Requiem

thank you. will try it. may I request sth too? May these blocked IPs redirected to another hub ?

DJ Bert

Tested that script. It works fine :D

Grtzzz
DJ Bert

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?

blackwings

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.


Requiem

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?

Pothead

#7
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

Requiem

#8
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

blackwings

#9
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


blackwings

#10
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.


SMF spam blocked by CleanTalk